Advertisement

Nehe lesson 17 - about glPopMatrix()

Started by June 12, 2009 05:06 AM
1 comment, last by wil_ 15 years, 5 months ago
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. +
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.
Advertisement
Ok, that works when I set back the modelview matrix to current mode, thanks !

This topic is closed to new replies.

Advertisement