PushMatrix, PopMatrix
Hi, i wrote following source code, it works alomost well, I have the squad before my camera even if i move or rotate the camera. But there is a small problem. If i move camera in way of axe Y, or i rotate it , the quad is moving. If i move the camera on axe Y so just a little bit. Does somebody know how could i make it work ?
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glRotatef(0,1,0,0);
glRotatef(0,0,1,0);
glRotatef(0,0,0,1);
glLoadIdentity();
glOrtho(0,100,0,133,-10,10);
glMatrixMode(GL_MODELVIEW);
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3f(0,10,0.1);
glVertex3f(100,10,0.1);
glVertex3f(100,0,0.1);
glVertex3f(0,0,0.1);
glEnd();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
I don''t know if this helps, but....
What''s the point in doing all these lines
glRotatef(0,1,0,0);
glRotatef(0,0,1,0);
glRotatef(0,0,0,1);
You seems to rotate about every axis in 0 degrees?
And you use pushMatrix(); and then LoadIdentity()? If you''re going to reset to Identity Matrix anyway, why bother push the Matrix.
Anyway, I''d rather write something more like this....
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,100,0,133,-10,10);
glMatrixMode(GL_MODELVIEW);
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3f(0,10,0.1);
glVertex3f(100,10,0.1);
glVertex3f(100,0,0.1);
glVertex3f(0,0,0.1);
glEnd();
What''s the point in doing all these lines

glRotatef(0,1,0,0);
glRotatef(0,0,1,0);
glRotatef(0,0,0,1);
You seems to rotate about every axis in 0 degrees?
And you use pushMatrix(); and then LoadIdentity()? If you''re going to reset to Identity Matrix anyway, why bother push the Matrix.
Anyway, I''d rather write something more like this....
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,100,0,133,-10,10);
glMatrixMode(GL_MODELVIEW);
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3f(0,10,0.1);
glVertex3f(100,10,0.1);
glVertex3f(100,0,0.1);
glVertex3f(0,0,0.1);
glEnd();
ok, firstly, it's good practise to never use the projection matrix for anything other than projection..
secondly, the use of glPush/Pop matrix is so you can save the current matrix for use at a later time... in effect, a way to 'undo' transofrmations you make...
ie, a prime example of this is a camera - scene graph style system...
ie,
all in modelview btw,
load matrix - camera
push matrix (save the camera matrix)..
mult matrix - object1 (move to where object1 is from the camera)
draw object 1...
pop matrix (we don't care about object1's position anymore) - in effect reload the camera
push matrix (save the camera again)
mult matrix - object2
etc...
does this help clear up the use of push/pop matrix? if it doesn't I can try a bit harder
for a more general view, a copy of the current matrix is simply being pushed onto the top of a statck of matrices when calling pushMatrix, and popped off the top and loaded with popMatrix..
| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |
[edited by - RipTorn on November 26, 2002 12:09:09 AM]
secondly, the use of glPush/Pop matrix is so you can save the current matrix for use at a later time... in effect, a way to 'undo' transofrmations you make...
ie, a prime example of this is a camera - scene graph style system...
ie,
all in modelview btw,
load matrix - camera
push matrix (save the camera matrix)..
mult matrix - object1 (move to where object1 is from the camera)
draw object 1...
pop matrix (we don't care about object1's position anymore) - in effect reload the camera
push matrix (save the camera again)
mult matrix - object2
etc...
does this help clear up the use of push/pop matrix? if it doesn't I can try a bit harder

for a more general view, a copy of the current matrix is simply being pushed onto the top of a statck of matrices when calling pushMatrix, and popped off the top and loaded with popMatrix..
| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |
[edited by - RipTorn on November 26, 2002 12:09:09 AM]
It doesn''T work, I wrote that 
I''m think that the quad is drawn behind the camera => I need to get the camera in pushmatrix to x0,y0,z0 and 0 angle on x,y,z, loadidentity should do it. bat anyway it still doesn''t work
glLoadIdentity();
glPushMatrix();
glLoadIdentity();
glOrtho(0,100,0,133,-10,10);
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3f(0,10,1);
glVertex3f(100,10,1);
glVertex3f(100,0,1);
glVertex3f(0,0,1);
glEnd();
glPopMatrix();

I''m think that the quad is drawn behind the camera => I need to get the camera in pushmatrix to x0,y0,z0 and 0 angle on x,y,z, loadidentity should do it. bat anyway it still doesn''t work
glLoadIdentity();
glPushMatrix();
glLoadIdentity();
glOrtho(0,100,0,133,-10,10);
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3f(0,10,1);
glVertex3f(100,10,1);
glVertex3f(100,0,1);
glVertex3f(0,0,1);
glEnd();
glPopMatrix();
It doesn''T work, I wrote that 
I''m think that the quad is drawn behind the camera => I need to get the camera in pushmatrix to x0,y0,z0 and 0 angle on x,y,z, loadidentity should do it. bat anyway it still doesn''t work
glLoadIdentity();
glPushMatrix();
glLoadIdentity();
glOrtho(0,100,0,133,-10,10);
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3f(0,10,1);
glVertex3f(100,10,1);
glVertex3f(100,0,1);
glVertex3f(0,0,1);
glEnd();
glPopMatrix();

I''m think that the quad is drawn behind the camera => I need to get the camera in pushmatrix to x0,y0,z0 and 0 angle on x,y,z, loadidentity should do it. bat anyway it still doesn''t work
glLoadIdentity();
glPushMatrix();
glLoadIdentity();
glOrtho(0,100,0,133,-10,10);
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3f(0,10,1);
glVertex3f(100,10,1);
glVertex3f(100,0,1);
glVertex3f(0,0,1);
glEnd();
glPopMatrix();
It doesn''T work, I wrote that 
I''m think that the quad is drawn behind the camera => I need to get the camera in pushmatrix to x0,y0,z0 and 0 angle on x,y,z, loadidentity should do it. bat anyway it still doesn''t work
glLoadIdentity();
glPushMatrix();
glLoadIdentity();
glOrtho(0,100,0,133,-10,10);
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3f(0,10,1);
glVertex3f(100,10,1);
glVertex3f(100,0,1);
glVertex3f(0,0,1);
glEnd();
glPopMatrix();

I''m think that the quad is drawn behind the camera => I need to get the camera in pushmatrix to x0,y0,z0 and 0 angle on x,y,z, loadidentity should do it. bat anyway it still doesn''t work
glLoadIdentity();
glPushMatrix();
glLoadIdentity();
glOrtho(0,100,0,133,-10,10);
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3f(0,10,1);
glVertex3f(100,10,1);
glVertex3f(100,0,1);
glVertex3f(0,0,1);
glEnd();
glPopMatrix();
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement