Hi,
I have come this piece of code and I don’t really understand why do I need to load the identity matrix after the glPopMatrix?
If I comment it out it doesn’t work as it should. The code uses keyboard to move the camera view around.
This is where a matrix is push onto the stack( I believe it is the MODELVIEW identity matrix)
glViewport(0.f, 0.f, SCREEN_WIDTH, SCREEN_HEIGHT);
//initialize Project Matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho( 0.0 , SCREEN_WIDTH , SCREEN_HEIGHT , 0.0 , 1.0 , -1.0);
//initialize Modelview Matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
And this is where I pop the matrix.
glMatrixMode(GL_MODELVIEW);
//Take saved matrix off the stack and reset it
glPopMatrix();
glLoadIdentity();
//Move camera to position
glTranslatef( -gCameraX, -gCameraY, 0.f );
//Save default matrix again with camera translation
glPushMatrix();
why is the identity matrix is necessary after poping the stack?
Thanks
P.S this is not the complete code, if it is unclear let me know.