glPushMatrix() or glLoadIdentity() ??
Hiya!
Short and simple:
Which should be used where? -Or is it the exact same?
Kindly,
Søren Olesen
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
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
----Eurosprt1--Pilot Extrodinaire
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
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
November 01, 2000 05:39 AM
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
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
Yes, yes
Well, then it would be stupid to put more than one glLoadIdentity() in my render code?
Mvh
Søren Olesen
Well, then it would be stupid to put more than one glLoadIdentity() in my render code?
Mvh
Søren Olesen
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
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
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement