Funky glTranslate, glPush & PopMatrix effects
I have several squares flying around the screen, each with it''s own x, y, and z positions. Originally, the draw function for each box was as follows:
glBegin(GL_QUADS);
{
glColor3f(0.0, 0.0, 1.0);
glVertex3f(xPos + 0.0, yPos + 0.0, zPos + 0.0);
glVertex3f(xPos + 1.0, yPos + 0.0, zPos + 0.0);
glVertex3f(xPos + 1.0, yPos + 1.0, zPos + 0.0);
glVertex3f(xPos + 0.0, yPos + 1.0, zPos + 0.0);
}
glEnd();
And that worked fine, each box was drawn in the correct location. However, I wanted to change the draw function to look like this:
glPushMatrix();
glTranslatef(xPos, yPos, zPos);
glBegin(GL_QUADS);
{
glColor3f(0.0, 0.0, 1.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glVertex3f(1.0, 1.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
}
glEnd();
glPopMatrix();
I thought that this would produce the exact same results, and be easier to read and faster to execute. But what ends up happening is that all of the boxes get drawn on top of eachother, in the position of the last box in my linked list of boxes.
Can anyone spot what I am doing wrong?
I even put the line "cout << xPos << yPos << zPos << endl;" in there and each box _does_ retain its individual position, it just doesn''t get drawn there.
Thanks for any help.
--Riley
theres nothing wrong with the code u posted (except u dont really need the brackets).
post more code esp before
glPushMatrix();
glTranslatef(xPos, yPos, zPos);
glBegin(GL_QUADS);
http://members.xoom.com/myBollux
post more code esp before
glPushMatrix();
glTranslatef(xPos, yPos, zPos);
glBegin(GL_QUADS);
http://members.xoom.com/myBollux
Thanks for looking at that - I finally traced down the problem. I had included some sample drawing code from the nehe tutorials and had evidently not done a particularly thourough job of deleting it all. A glPushMatrix was left but there was no corresponding glPopMatrix.
Thanks again~
/riley
Thanks again~
/riley
--Riley
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement