Jump to content
  • Advertisement

Archived

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

soreno

glPushMatrix() or glLoadIdentity() ??

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

Hiya! Short and simple: Which should be used where? -Or is it the exact same? Kindly, Søren Olesen

Share this post


Link to post
Share on other sites
Advertisement
Soren,

the glPushMatrix() is combined with glPopMatrix() to save the previous state the matrix (machine) was in before you do the transformation you would like to perform. glLoadIdentity() is used to rest the coordinate system that is used. Hope that helps you understand those functions alittle better.

Euro

Share this post


Link to post
Share on other sites
Hi!

Yes, I Know. But when should I use glLoadIdentity() when should you use glPushMatrix combined with glPopMatrix ? -Is there a specific guideline?

Mvh
Søren Olesen

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
glLoadIdentity resets the matrix to one that has no effect on the points you pass to OpenGL.

glPush/PopMatrix are for doing hierarchial transformations. If you wanted to draw a car in a game you might do this...

// Start of frame - reset transformations
glLoadIdentity ();

// Start drawing car
glPushMatrix ();
glTranslatef (car_x, car_y, car_z);

// Draw car here
draw_car_body ();

// Stop drawing car
glPopMatrix ();


Note that you should make sure that there are the same number of pops as pushes.

- Peter

Share this post


Link to post
Share on other sites
Yes, yes

Well, then it would be stupid to put more than one glLoadIdentity() in my render code?

Mvh
Søren Olesen

Share this post


Link to post
Share on other sites
not really

for example

//start, we set Matrix to 1
glLoadIdentity();

glTranslatef(0,0,-6);//in every NeHe Tut with perspective
glRotatef(xrot,1,0,0);//


then we draw there all our things (with Push and Pop, when you whant, like in the example with the car)

glTextOut(10,10,"Hello World");


and glTextOut is
void glTextOut(x,y,char*name)
{
glPushMatrix();
glLoadIdentity();
glTranslatef(x,y,-6);
glCallLists(text);//ok, thats shorten much
glPopMatrix();
}


we wanna play, not watch the pictures

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!