independent objects

I want to move 3 objects independently. The problem is, when rotating one, the others move too.
Now I tried to solve the problem like this:

glLoadIdentity();
glTranslatef(x1, y1, z1);
/* Draw first object /
glLoadIdentity();
glTranslatef(x2, y2, z2);
/
Draw second object /
glLoadIdentity();
glTranslatef(x3, y3, z3);
/
Draw third object */

Before I had only one glLoadIdentity, now I used 3. But now the last two objects are not visible any more! What do I do wrong? :confused:

You should use pushMatrix/popMatrix pairs instead of glLoadIdentity.

Modified code:

 
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glTranslatef(x1, y1, z1);
/* Draw first object */
glPopMatrix();
glPushMatrix();
glTranslatef(x2, y2, z2);
/* Draw second object */
glPopMatrix();
glPushMatrix();
glTranslatef(x3, y3, z3);
/* Draw third object */
glPopMatrix();

Always be sure to call glPushMatrix and glPopMatrix in pairs or you may overflow the matrix stack.

THANK YOU!!! It works! :smiley: