# Simple translate error

This topic is 3531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 :*

##### Share on other sites
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();}

##### Share on other sites
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

##### Share on other sites
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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 11
• 13
• 9
• 9
• ### Forum Statistics

• Total Topics
634081
• Total Posts
3015385
×