opengl matrix stack question

Started by
2 comments, last by ECKILLER 24 years, 1 month ago
hi, ok i think i see why to use glPushMatrix and pop but lets say you push 3 matrices down(3+identity = 4) and do some stuff then you want the one right on top of the identity matrix. Do you have to call glPopMatrix twice? Is there an easier navigation to the stack??? I read that one of the stacks goes to 32 or something, that would be a pain to have to call the pop function a whole bunch of times to get the one you want and hard to follow as well. ECKILLER
ECKILLER
Advertisement
I don''t think there is an easy way of popping the complete stack. However, a call to glPopMatrix() is very fast, most likely only a decrease of a variable.

The navigation of the matrix stack is not that hard to follow. Just think of it as the curly brackets of the C code, you can even do some indentation between glPushMatrix() and glPopMatrix() to make it more readable.

Here''s an example:

glPushMatrix();  glBegin();    glVertex();    glVertex();    glVertex();  glEnd();  glPushMatrix();    glBegin();      glVertex();      glVertex();      glVertex();    glEnd();  glPopMatrix();glPopMatrix();


Arguments are ommited.
>Is there an easier navigation to the stack?

To go back to identity matrix, just one call is enough:

glLoadIdentity();

James
jamesH: Bad boy!

If you do it that way you''ll soon overflow the matrixstack. Of course if you ignore using glPushMatrix() and glPopMatrix() all together, you can use glLoadIdentity() to clear the matrix, but glPushMatrix() must be followed by an equal number of glPopMatrix().

This topic is closed to new replies.

Advertisement