# Assemble 2 square and translate

Hi all,
I want to assemble 2 square and after translate them with z-axis :
But I’m beginner and don’t remember how to do :

glPushMatrix();

glPushMatrix();
glTranslatef(0f, 0f, 0f);
draw(gl,iSquare1, 2);

glPushMatrix();
glTranslatef(1f, 0f, 0f);
draw(gl,iSquare2, 2);

glPopMatrix();
glTranslatef(0f, 0f, -35f);
glPushMatrix();

-> It doesn’t work

I asssume you push the view&projection matrices here to restore them later and draw something else on the current transformation?

So you load an identity matrix into what exactely? Modelview?
Why do push the view & projection matrices again?
That glTranslatef uses zero on every axis and has no effect.

[QUOTE=McCorwin;1283066]
glPushMatrix();
glTranslatef(1f, 0f, 0f);
draw(gl,iSquare2, 2);
[/QUOTE]
You load idenitity again and then you push the matrices again. Why?

At this point you called glPushMatrix 3 times.

Are you sure you know how a stack works?

You restore the previous view & projection matrices by calling glPopMatrix. This includes the one you previously
set to identity using glLoadIdentity() before pushing.

You then apply a transformation along the Z axis. Since I don’t know what your current matrix mode is and what
your modelview & projection matrices look like, I cannot predict what effect this has.

If your view & projection matrices are both identity, this transforms whatever you draw next outside the unit cube.

In fact, I don’t see you drawing anything. You push your matrices again??

[QUOTE=McCorwin;1283066]
-> It doesn’t work[/QUOTE]

If this is your entire drawing loop, you increase your matrix stack by 3 view-projection matrix pairs every iteration.
Your usage of pushmatrix and popmatrix makes no sense. It would be interesting what your transformation and projection
matrices looked like in the beginning and what you expect to happen.