Jump to content
  • Advertisement

Archived

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

xDS4Lx

glPush/PopMatrix

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

Im wondering, when I call glPushMatrix() it preserves the state and pushes it on to the matrix stack right? Then if i cal glTranslate* and do other stuff, then glPopMatrix it moves me back to the position where I was before the glPush call right?

Share this post


Link to post
Share on other sites
Advertisement
So everytime i draw something like rendering a model or terrain i should call glPushMatrix, translate the terrain/model wherever i want it and rotate/scale it how i want, then when i finished drawing it call glPopMatrix and restore the modelview back to the original position?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by ZealousElixir
You can, but if you store the positions of your models in unrelative world space, you won''t have to. Most often you do though.


I''ve got 3 objects with the positions:

  
Obj1X = 5; Obj1Y = 3;
Obj2X = 1; Obj2Y = 2;
Obj3X = 3; Obj3Y = 4;


And when i draw them I do like this:


  
glPushMatrix();
glTranslatef(Obj1X, Obj1Y, 0);
// Draw Obj1;

glPopMatrix();

glPushMatrix();
glTranslatef(Obj2X, Obj2Y, 0);
// Draw Obj2;

glPopMatrix();

glPushMatrix();
glTranslatef(Obj3X, Obj3Y, 0);
// Draw Obj3;

glPopMatrix();


Is there another way?

Share this post


Link to post
Share on other sites
That''s a good way to do it. I recommend reading the chapter about transformations in the red book(there''s an online version somewhere).

Share this post


Link to post
Share on other sites
Yeah there''s another way. If all those objects are relative to a single coordinate system (i.e. they have no additional rotations or translations required to draw them), you don''t have to call glPush/Pop for each item. Like I said though, most of the time you will want them drawn independently of each other and the current modelview coordinate system. So, that method is fine.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!