Nehe lesson 17 - about glPopMatrix()
2 replies to this topic
Members - Reputation: 466
Posted 11 June 2009 - 11:06 PM
Hello first thanks for making such material available on Nehe. I met for the first time multiple use of glPopMatrix() in lesson 17 today : in custom function glPrint(..) we find something that looks a bit like that : glMatrixMode(GL_PROJECTION); glPushMatrix(); // set ortho matrix // ... glMatrixMode(GL_MODELVIEW); glPushMatrix(); // display stuff // ... glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); The author comments about the uses of popmatrix: "It's important to restore things in the opposite order you stored them in. " Which is the reverse order ? I thought it would mean pop the last matrix we pushed, and then the first one. When trying to do this (popping modelview matrix before projection matrix), the textured square displayed in the lesson disappears from my scene. I don't understand why, how it is connected to the order of calls to popmatrix. Does anyone know what is happening in that case ? Thanks in advance for any comment. +
Moderators - Reputation: 9367
Posted 11 June 2009 - 11:37 PM
The matrix modes have separate stacks, so it doesn't matter in which order you pop them. However, what does makes a difference is the current matrix mode after the code is executed. If you change the order, the matrices will be restored properly, but the active matrix is now the projection matrix and not the modelview matrix. If, further down the code, you assume the modelview is active, you're screwed.