Archived

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

soreno

glPushMatrix() or glLoadIdentity() ??

Recommended Posts

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
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
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