PUSHing and POPing matrices in OpenGL

Started by
3 comments, last by wolfman8k 23 years, 7 months ago
What does pushing and poping matrices in openGL do? I know it has something to do with the stack and saving matrices but I don''t know what it does exactly and what you''d need it for. Thanks, wolfman8k
Advertisement
The glPushMatrix and glPopMatrix calls are used to save/restore
the current matrices in the selected matrix mode
GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE.

glPushMatrix makes a copy of the current selected matrix
and pushes it onto a stack. You can then work on the
current matrix and alter it as you need.
When you call glPopMatrix it''s restores the last pushed
matrix to bein the current matrix - within that matrix
mode. Slightly convoluted but I think you get the idea.

I use it for keeping track of camera/model matrices.
What I do is I build the camera matrix at the start of the
frame into GL_MODELVIEW - then when I render an object, I
push the matrix onto the stack - make alterations for the
model transforms (and sub-models - using glPush aswell). Then
when I leave the rendering for the model I pop off the original
camera matrix - leaving things nice.

_Definately_ useful functions if used correctly.


--
Code..reboot..code..reboot..sigh!
MrF.--Code..reboot..code..reboot..sigh!
Perfectly agree with MrFlibble.

BTW, MrFlibble if you want to change your signature to :

Code..test..code..test..

Simply use BeOS

(I love BeOS, it makes me happily code in C and C++ with OpenGL and SDL)

-* So many things to do, so little time to spend. *-
-* So many things to do, so little time to spend. *-
also u can go ( its all the same jist)
glPushAttrib(GL_ALL_ATTRIBUTES?)
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE)
glEnable(GL_WIREFRAME?)
// draw someit that you want to be textured + wireframed
glPopAtrrib();
now the state is back to what it was before maybe lite maybe solid maybe not textured etc

for glPushAttrib the flag to push all the attributes is:

GL_ALL_ATTRIB_BITS

Generally its a define in the header which is all the
individual push masks OR''d together.

Never actually looked at that - learn something new everyday =)

Ingenu:
Aye might take a look into BeOS again sometime soon.
Though I''d rather use Linux really =)

Still trying to get XFree 4.0.1 working - problems with
windowmanagers crashing when I log in atm *sigh*

Anyway - I like my sig the way it is =)

--
Code..reboot..code..reboot..sigh!
MrF.--Code..reboot..code..reboot..sigh!

This topic is closed to new replies.

Advertisement