You Like My Tutorials? Click The Banner To Keep 'Em Coming!

glGameDeveloper(): The Game Developer's Source for OpenGL Coding
Main Menu
Latest News
Archived News
Tutorials
Links
E-Mail Me

Other
Message Board
My Guestbook

Tutorials -- Drawing Triangles
 


Drawing Triangles in OpenGL Page 2 of 4
< Previous Jump to Page: 1 | 2 | 3 | 4 Next >

The Code

Lets start with the code that sets up our matrices.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, (GLfloat) ww/(GLfloat) wh, 1, 700);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

This code first sets the matrixmode to GL_PROJECTION. Then it resets it to zero (LoadIdentity()) and sets up our perspective. This makes OpenGL render at a 45 degree viewing angle, and makes things look right depending on our window with and height (the ww and wh variables). The last 2 parameters set our near and far "clipping planes". These determine how far we can see in the 3d world.

After that, it sets us back to the MODELVIEW matrix and sets it to zero also. Finally, it clears our color buffer and depth buffer. Basically it sets everything back to zero again.

Drawing Triangles in OpenGL Page 2 of 4
< Previous Jump to Page: 1 | 2 | 3 | 4 Next >

This site best viewed with MS Internet Explorer 5.0 at 16-bit color and at least 800x600.

All Contents of this site are Copyright 1999, 2000 Joe Zimmerman. No part of this site (code, HTML, etc.) may be reproduced without my permission.

Click Here!