Simple translate error

Started by
2 comments, last by Lascha 14 years, 11 months ago
Hi, I don't quite understand why after calling glCallList, all my translatef calls dont work... CODE: GLuint glui=-1; for(unsigned int i=0;i<B.size();++i){ b = B; glui = R.terrainMap[b->terraintype]; pos = b->getPosition(); glTranslatef(pos.x,pos.y,0); //HERE translates only once for i=0 glCallList( glui ); //glTranslatef(-pos.x,-pos.y,0); } it translates pos.x & y only once and after calling List all translates are ignored. Loop works fine. CallLists are the simplest one ; p GLID = glGenLists(1); glNewList(GLID,GL_COMPILE); glBegin( GL_QUADS ); glVertex3f (-0.5, -0.5, 0.0); glVertex3f ( 0.5, -0.5, 0.0); glVertex3f ( 0.5, 0.5, 0.0); glVertex3f (-0.5, 0.5, 0.0); glEndList(); thx for response :*
Advertisement
Using glPushMatrix() you push (duplicate your current matrix) and then the translate function is called on the matrix that you pushed. Later you can pop the matrix back to your previous 'current' matrix with glPopMatrix(). I think this should solve it.

GLuint glui=-1;for(unsigned int i=0;i<B.size();++i){    b = B;    glui = R.terrainMap[b->terraintype];    pos = b->getPosition();    glPushMatrix();	        glTranslatef(pos.x,pos.y,0);        glCallList( glui );    glPopMatrix();}
yes, thats true, but i already tried inserting push/pop matrixes in many ways and it doesn't change anything. It still renders all objects from list in one point from first translation and the rest of the objects from other parts of the code are all translated by this one call.

i mean:
glPushMatrix();
glTranslatef(pos.x,pos.y,0);
glCallList( glui );
glTranslatef(666,69,44); //will still not work
glPopMatrix();
glTranslatef(-777,69,44); //will still not work

Weird, it should be working.

When you call translate the first time, it shifts the origin (top left point) for the matrix, thus with positive values as parameters the matrix will get smaller. So, maybe the second translate call /does/ work, but it might be going outside bounds. Make sure on that, put a watch on the pos parameter.

Also, try setting the origin of your rectangle (it's a rectangle right?) in the topleft instead of in the centre.

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


Also noticed you called glBegin( GL_QUADS ) but not glEnd(). I don't how it works like with lists, but try calling that one too.

It could also be that the glui variable is wrong. glCallList does nothing if the given parameter isn't defined. Use if( glIsList( glui ) == GL_TRUE ) to see if that parameter is in the list.

This topic is closed to new replies.

Advertisement