1. Cube Rotation openGL

Hi everyone,
I've drawn 5 sides of a cube all different colors. I want the cube to 'spin' in place toward it's right side. However, I can only get it to spin in place vertically or if I try to go to the right I have to rotate it about some Z-axis as well. Here is the code for the vertically spinning 'cube'. Any help is greatly appreciated.

Code:
```void draw ()
{
float z = 4;

glMatrixMode(GL_MODELVIEW);

glPushMatrix();

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glTranslatef(-3.0f, -3.0f, -10.0f);
glRotatef(angle, 0.0f, 0.0f, 4.5f);

// RED SQUARE (front)
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-0.5f, 0.5f, z);
glVertex3f(0.5f, 0.5f, z);
glVertex3f(0.5f, -0.5f, z);
glVertex3f(-0.5f, -0.5f, z);

// BLUE SQUARE (top)
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(-0.5f, 0.5f, z);
glVertex3f(0.5f, 0.5f, z);
z -= 1;
glVertex3f(0.5f, 0.5f, z);
glVertex3f(-0.5f, 0.5f, z);

// GREEN SQUARE (back)
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-0.5f, -0.5f, z);
glVertex3f(0.5f, -0.5f, z);
glVertex3f(0.5f, 0.5f, z);
glVertex3f(-0.5f, 0.5f, z);

z += 1;

// WHITE SQUARE (right)
glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(0.5f, 0.5f, z);
glVertex3f(0.5f, -0.5f, z);
z -= 1;
glVertex3f(0.5f, -0.5f, z);
glVertex3f(0.5f, 0.5f, z);

z += 1;

// YELLOW SQUARE (left)
glColor3f(1.0f, 1.0f, 0.0f);
glVertex3f(-0.5f, 0.5f, z);
glVertex3f(-0.5f, -0.5f, z);
z -= 1;
glVertex3f(-0.5f, -0.5f, z);
glVertex3f(-0.5f, 0.5f, z);

glEnd();

glPopMatrix();
if (angle < 360) angle += 5.0f;
else angle = 0.0f;

SDL_GL_SwapBuffers();
} // end draw ()```
Also, my settings are:

Code:
```void initGLsettings ()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable(GL_DEPTH_TEST);
glViewport(0.0f, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT);
glMatrixMode(GL_PROJECTION);
gluPerspective(60.0f, 1.0f*SCREEN_WIDTH/SCREEN_HEIGHT, 0.1f, 125.0f);
glMatrixMode(GL_MODELVIEW);
}```
edit: I said if I go to the right it must about some Z-axis as well. I mean it has to be about a large y-axis.

2. If you want an object to rotate around a point other than it's center, first translate to the desired point, perform your rotation, and then translate to world coordinates.

You could then, if needed, translate to another point of rotation and then rotate. This would cause the object to rotate around the point in world space.

3. Just a note, there's no need to keep selecting the model view matrix. You should be doing most of your work on it anyway, if you need to modify another matrix such as the texture matrix then select the texture matrix do your stuff then reselect the model view matrix. The OpenGL FAQ recommends this practice too.

Last time I checked cubes had 6 sides

4. Originally Posted by Bubba
If you want an object to rotate around a point other than it's center, first translate to the desired point, perform your rotation, and then translate to world coordinates.

You could then, if needed, translate to another point of rotation and then rotate. This would cause the object to rotate around the point in world space.
Thanks for the response,
The point which the cube rotates isn't a problem, it's the direction. I can rotate it about it's center, but it spins counter-clockwise like a square, where as I want to it spin horizontally in place (the left side comes at you as it goes around and follows the right around but the center of the cube is the same coordinate). Sorry if i misinterpreted anything you said. You make a very useful point though for future reference.

Also zacs thanks for the information. I modified the code so that the modelview matrix is selected in the draw () function only, and no other matrices are ever specified.

5. The direction of rotation is based on your yaw, pitch, and roll. If it is rotating the wrong direction then negating yaw should give you the correct direction.