Code:
// positioned by top left corner.
void DrawCube(float xPos, float yPos, float zPos, float width, float height, float depth)
{
float w = width + xPos;
float h = height + yPos;
float d = depth + zPos;
glBegin(GL_QUADS);
// front
glVertex3f(xPos, yPos, zPos);
glVertex3f(w, yPos, zPos);
glVertex3f(w, h, zPos);
glVertex3f(xPos, h, zPos);
// back
glVertex3f(xPos, yPos, d);
glVertex3f(w, yPos, d);
glVertex3f(w, h, d);
glVertex3f(xPos, h, d);
// left
glVertex3f(xPos, yPos, zPos);
glVertex3f(xPos, yPos, d);
glVertex3f(xPos, h, d);
glVertex3f(xPos, h, zPos);
// right
glVertex3f(w, yPos, zPos);
glVertex3f(w, yPos, d);
glVertex3f(w, h, d);
glVertex3f(w, h, zPos);
// top
glVertex3f(xPos, yPos, zPos);
glVertex3f(xPos, yPos, d);
glVertex3f(w, yPos, d);
glVertex3f(w, yPos, zPos);
// bottom
glVertex3f(xPos, h, zPos);
glVertex3f(xPos, h, d);
glVertex3f(w, h, d);
glVertex3f(w, h, zPos);
glEnd();
}