here is the reshape funcion I have, I know it works but I just dont understand how??
void reshape(int w, int h)
{
glPushMatrix();
glViewport(0, 0, (GLsizei)w, (GLsizei)h) ;
glMatrixMode(GL_PROJECTION) ;
glLoadIdentity() ;
gluPerspective(45, (GLfloat)w/(GLfloat)h, 0.1, 100.0) ;
glMatrixMode(GL_MODELVIEW) ;
glLoadIdentity() ;
glPopMatrix();
}
in the entire program, this is the only place where gluPerspective appears and sets the matrix in perspective mode, but below that line there is glLoadIdentity, which resets the matrix, then theres glPopMatrix, which pops the matrix stored at the beginning of reshape function, so howcome when I enter the display function and draw something:
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity();
glRotatef(g_lookupdown,1.0f,0,0); //look up and down
glRotatef(sceneroty,0,1.0f,0); //look side to side
glTranslatef(xtrans, ytrans, ztrans); //moving all directions
glTranslatef(0,0,-5.0) ;
glColor4f(1.0, 1.0, 0.0, 1.0);
glutWireCube(1);
…
…
glutSwapBuffers();
they are in perspective mode and not reset??
I also need better explaination of
glMatrixMode(GL_PROJECTION) ;
and
glMatrixMode(GL_MODELVIEW) ;
those tutorials and documents do not explain enough and I think understanding these will explain my question above. I know these store the matrix configuation made by the lines of code above it, but when and how are they “popped” back into effect?
How does GL_PROJECTION and GL_MODELVIEW differ and can I just use one in the reshape function and not the other? how does that change the way my objects look?
Any help would be greatly appreciated.
Newbie