# Problem rotating cubes in opengl

I'm trying to make a simple 3d tetris game, but I'm having trouble rotating my blocks. The blocks are made up of 4 cubes (drawn with glutSolidCube()). I can't figure out how I can rotate them and still have the axes point in the right direction for the cubes' movement.

This is the simplest form of what I've tried that clearly illustrates the problem when I run it

for(int i=0; i<4; i++){
glPushMatrix();
glRotatef(90.0, 1,0,0);
glTranslatef(cubes[i]->xPos, cubes[i]->yPos, cubes[i]->zPos);
cubes[i]->draw();
glPopMatrix();
}


And this not only rotates the block, but rotates the whole system in the sense that now, the blocks are rotated in the right direction, but move in from the side rather than the top as if the axes have been rotated as well. I've tried first translating to the point where they start falling, rotating and translating back, but they still just go sideways. (not included in the sample because the start location isn't the main problem here)

I sort of understand why this happens, but I don't know how to fix it.

What you aren't showing is how the cubes' falling translation is applied. From your description of the effects, it is occurring after the rotation; so you are either translating in ->draw() or updating the yPos etc. coordinates. The "graphics" fix to your problem is to apply the falling motion before your glRotate.
Therefore, you are going to want to compute the rotation yourself, not delegate it to OpenGL. My recommendation would be to actually change the configuration of the cubes — that is, change xPos, yPos, and zPos according to the rotation. Since you are only doing 90° rotations, this is especially simple. This means your collision tests do not have to think about rotations.