• Advertisement

Archived

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

glPushMatrix() question

This topic is 5124 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

When using glPushMatrix() with multiple objects does that push a new coordinate space for that object on the stack? I ask this because I have a bunsh of objects on screen and they seem to be layered on top of each other. Also, how could I fix not having them drawn in a layered fashion but still push and pop matrices? Thanks a lot.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
it s not clear what you mean... for me...

If you Push your Matrix you save the current Matrix. Then you can translate, rotatef what ever and THEN-> You pop (load) your old Matrix. And the transformations, rotations whatever are not there for all the Object you draw after popping you old Matrix

Dunno if pop / push saves / loads the matrix I forget it always

MFG

Share this post


Link to post
Share on other sites
quote:
Original post by jon723
When using glPushMatrix() with multiple objects does that push a new coordinate space for that object on the stack? I ask this because I have a bunsh of objects on screen and they seem to be layered on top of each other. Also, how could I fix not having them drawn in a layered fashion but still push and pop matrices?


Thanks a lot.


I think you''re probably doing something wrong with your depth testing if they appear "layered". I''m not entirely sure what you''re talking about, though.

Share this post


Link to post
Share on other sites
quote:
Original post by jon723
When using glPushMatrix() with multiple objects does that push a new coordinate space for that object on the stack? I ask this because I have a bunsh of objects on screen and they seem to be layered on top of each other. Also, how could I fix not having them drawn in a layered fashion but still push and pop matrices?


glPushMatrix makes a copy of the current modelview matrix (coordinate space if you like) on the top of the stack. You can remove it from the stack and make it current again with glPopMatrix. The rest of your question makes no sense, so I can''t help you with it.

Share this post


Link to post
Share on other sites
I just want to add a practical example, in case you don''t understand yet: Lets say you''re about to draw something: a box.
You want to draw this box at coordinates (10, 10, -5). But after that you want to draw something else as well, at coordinates (-10, 0, 0).

without push/pop matrix, you''d have to do this:

gltranslatef( 10, 10, -5)

//draw the object
glBegin()
etc...
glEnd()

//draw the other one

glTranslatef( -20, -10, 5) //make up for the last translation
glBegin()
etc...
glEnd()


That''s a pain though, because I''d have to keep track of where I last translated to. PushMatrix() / PopMatrix effectively does that for you.

//draw first one

glPushMatrix()//save a copy of modelview matrix

glTranslatef(10, 10, -5);// translate to the object''s coordinates
glBegin()
etc...
glEnd()


glPopMatrix(); //load the last matrix saved

//draw second one

glPushMatrix()//save a copy of modelview matrix

glTranslatef(-10, 0, 0);// translate to the object''s coordinates
glBegin()
etc...
glEnd()

glPopMatrix


you can even do rotations and scaling inside a push/pop block. It will only affect vertices drawn after and up to the next popMatrix call.

Share this post


Link to post
Share on other sites

  • Advertisement