>> glMatrixMode (GL_PROJECTION);
This selects which matrix-stack the subsequent calls modify. There are 3 Matrix-Stacks in OpenGL
GL_MODELVIEW - used to setup the camera, move/scale/rotate your objects
GL_PROJECTION - the kind of projection is defined here, the near and far-plane, the fov (field of view), Orthographic or Perspective Projection, the width and height (in pixels) of the Viewport etc.
GL_TEXTURE - this is not important here, actually i never used it myself ;)
Calls that modify the top matrix on the matrix-stack in your program are for instance:
glLoadIdentity
gluOrtho2D
others are:
glRotate
glTranslate
glMultMatrix
So first you select the Projection-Matrix with:
glMatrixMode (GL_PROJECTION);
Then you load the identity matrix to the top Projection Matrix (This is a kind of reset) with this:
glLoadIdentity();
Then this call modifies the Projection-Matrix to setup the viewport (actually it loads a matrix to the top matrix in the Projection-Matrix-Stack
gluOrtho2D(0.0, (GLdouble)newWidth, 0.0, (GLdouble)newHeight);
Then you clear the color-buffer, that does not necessarily need to be there, you can remove it
glClear(GL_COLOR_BUFFER_BI
Normally you should switch back to the ModelView-matrix Stack at the end of the reshape function:
glMatrixMode (GL_PROJECTION);
Then you can safely call glLoadIdentity/glRotate/gl
Hope it helps a bit :)
ike
Main Topics
Browse All Topics





by: ikeworkPosted on 2009-09-10 at 11:47:54ID: 25303094
Hey valleytech,
Whenever the window is resized, the projection matrix is being setup by calling gluOrtho2D.
What excactly do you not understand?
ike