Sorry, this is probably a dumb question but I just started w/ openGL this week!

I’m trying to draw a cube and rotate it in various directions responding to keyboard input. The problem is that the surfaces don’t seem to display correctly–eg, when I rotate, surfaces appear and disappear in ways I don’t expect from a rotating cube. (But I tried using GL_LINES instead of GL_QUADS to draw an “empty” cube and things looked ok…)

I was thinking maybe the problem was the order I was drawing the squares–does this matter at all, or is it another problem? Here’s my code for the drawing function:

void DrawCube(HDC hDC,float x,float y,float z,float len)

{

clear(); //clears buffer

glPushMatrix();

glRotatef(rotate[0].angle,1.0f,0,0); //x,y,z rotations

glRotatef(rotate[1].angle,0,1.0f,0);

glRotatef(rotate[2].angle,0,0,1.0f);

glBegin(GL_QUADS);

//front face:

glColor3f(1.0f,0.0f,0.0f);

glVertex3f(x, y, z);

glVertex3f(x+len, y, z);

glVertex3f(x+len, y-len, z);

glVertex3f(x, y-len, z);

```
//back face:
glColor3f(0.5f,0.5f,0.0f);
glVertex3f(x, y, z-1);
glVertex3f(x+len, y, z-1);
glVertex3f(x+len, y-len, z-1);
glVertex3f(x, y-len, z-1);
//left face:
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(x,y,z-1);
glVertex3f(x,y-len,z-1);
glVertex3f(x,y-len,z);
glVertex3f(x,y,z);
//right face:
glColor3f(0.0f,0.5f,0.5f);
glVertex3f(x+len,y,z);
glVertex3f(x+len,y,z-1);
glVertex3f(x+len,y-len,z-1);
glVertex3f(x+len,y-len,z);
//top face:
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(x,y,z);
glVertex3f(x,y,z-1);
glVertex3f(x+len,y,z-1);
glVertex3f(x+len,y,z);
//bottom face:
glColor3f(0.5f,0.0f,0.5f);
glVertex3f(x,y-len,z);
glVertex3f(x,y-len,z-1);
glVertex3f(x+len,y-len,z-1);
glVertex3f(x+len,y-len,z);
```

glEnd();

glPopMatrix();

SwapBuffers(hDC);

}

Thanks,

Jay