Pushing and Popping

Started by
2 comments, last by subflood 19 years ago
Why would you want to push and pop matrices? I mean I don't really understand the purpose of the commands. In my code I draw a bunch of quads and I tried using the command glPushMatrix(); before I start the drawing and glPopMatrix() after the drawing is completed but they have no effect. Can anyone give me a scenario where using these commands would be usefult? thanks.
Advertisement
pretty simplistic use of them, but suppose you have a bunch of objects to render, and the code to render these objects uses gl calls that change the position of the origin, like glTranslatef and glRotatef. To return to the normal origin after drawing, you'd have to reverse all of the calls (so if you move 3 units down the z axis, you have to move 3 units back up, and so on). Alternatively, you could push on a new matrix before you draw each object, and set it to the identity, and then pop it off after uve drawn said object. When u get to push one on for the next object, you are back where you started, and you dont have to do any wierd reversing of stuff.
hope that helps!


Scott
Yeah, the whole point of push and pop is that when you push the matrix it effectively saves the state of the matrix, so you can change it , render some things, and when you pop it you get the original matrix back. It's just a stack.
My stuff.Shameless promotion: FreePop: The GPL god-sim.
Thanks for the good explenation.

This topic is closed to new replies.

Advertisement