Archived

This topic is now archived and is closed to further replies.

glPushMatrix() and glPopMatrix();

This topic is 5826 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sup All, I''ve just started OpenGL from the AWESOME OpenGL Game Programming book. I have a question about the glPush and Pop functions. It is unclear to me what it exactly does. To my understanding it just resets the object creation position which was changed by glTranslatef(...) to the previous position. However, in chapter 5 in the robot example, removing glPushMatrix() from the DrawArm function has no effect. Correct me if I''m wrong and please try to explain my observation. Thanks, mAdMaLuDaWg

Share this post


Link to post
Share on other sites
glPushMatrix() puts the current object creation position on top of the stack so you can "save it for later". Say that you need to glTranslate the drawing position to draw something on the side of the screen, then when you want to move back you don''t know where you came from, right? If you use glPushMatrix() before you do a glTranslate, then you can easily retreave your old drawing position again with the pop function. Do you know what a stack is?

Share this post


Link to post
Share on other sites
think of it like a stack of books. you can "push" the book youre working with to the top of the stack (afaik the stack grows downward, but thats irrelevant) to work on another book for a moment. then once done you can "pop" that book and resume working with it.

Share this post


Link to post
Share on other sites