PDA

View Full Version : Why I need pop and push in open gl



MOON-GIRL
12-16-2002, 07:23 AM
hi every body http://www.opengl.org/discussion_boards/ubb/smile.gif


why i need pop and push in open gl

and when


best regards

Moon_Girl

nexusone
12-16-2002, 07:59 AM
Think of push/pop as matrix save/load, but works like a stack function.
Which means that the last item saved will be the first item to be be pulled back off the stack when a pop is called.

Example I have to objects, both I want to have a 45 degree rotation done on both, but want to do a 5 unit translation on one and a 10 unit translation on the other.

glRotatef(45, 1.0, 1.0, 1.0);

glPushMatrix();
glTranslatef( 5.0, 0.0, 0.0);
draw_object1();
glPopMatrix(); // I have restored the matrix back to before the translate was called.

glPushMatrix();
glTranslatef(10.0, 0.0,0.0);
draw_object2();
glPopMatrix();

Both objects get a 45 degree rotation, but each one has its own translate. Note you can also rotate and scale inside push/pop.

If you do not use push/pop matrix placing objects in your 3D world becomes very complicated. Since the next matrix rotations/translations would be ralative to the last ones.

With push/pop, you can more easly manage your objects.

glPushMatrix();
rotate/translate etc.
Draw_object
glPopMatrix();

draw next objects

For a good example check out my clock program: http://www.angelfire.com/linux/nexusone/index.html



Originally posted by MOON-GIRL:
hi every body http://www.opengl.org/discussion_boards/ubb/smile.gif


why i need pop and push in open gl

and when


best regards

Moon_Girl



[This message has been edited by nexusone (edited 12-16-2002).]

MOON-GIRL
12-16-2002, 08:49 AM
thaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaank you very much http://www.opengl.org/discussion_boards/ubb/smile.gif http://www.opengl.org/discussion_boards/ubb/smile.gif

i understooood now http://www.opengl.org/discussion_boards/ubb/smile.gif

best regards
Moon_Girl

[This message has been edited by MOON-GIRL (edited 12-16-2002).]