Basic: Pyramids and Cubes... Error while defining Cube's vertices. Where I was wrong?

I follow Nehe and GT Tutorials. While defining vertices, I’m getting a negative traingle which is cutting off the bottom of the sides of Cube. Why is it? Where I was wrong?

int DrawGLScene(GLvoid) // Here’s Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer

glLoadIdentity();
glTranslatef(1.5f,0.0f,-7.0f); // Move Right 3 Units
glRotatef(rquad,1.0f,1.0f,1.0f);
glBegin(GL_QUADS);         // Draw A Cube
        //Front Facing
    glColor3f(1.0f, 1.0f, 0.0f);
    glVertex3f(-1.0f, 1.0f, 1.0f);              // Top Left
    glVertex3f( 1.0f, 1.0f, 1.0f);              // Top Right
    glVertex3f( 1.0f,-1.0f, 1.0f);              // Bottom Right
    glVertex3f(-1.0f,-1.0f, 1.0f);              // Bottom Left
    //Right Facing
    glColor3f(1.0f,0.0f,0.0f);
    glVertex3f(1.0f,1.0f,1.0f);                //Top Left
    glVertex3f(1.0f,-1.0f,1.0f);            //Bottom Left
    glVertex3f(1.0f,1.0f,-1.0f);            //Top Right
    glVertex3f(1.0f,-1.0f,-1.0f);            //Bottom Right
        //Rear Facing
    glColor3f(0.0f,1.0f,1.0f);
    glVertex3f(1.0f,1.0f,-1.0f);            //Top Left
    glVertex3f(1.0f,-1.0f,-1.0f);            //Bottom Left
    glVertex3f(-1.0f,1.0f,-1.0f);            //Top Right
    glVertex3f(-1.0f,-1.0f,-1.0f);            //Bottom Right
        //Left Facing
    glColor3f(1.0f,0.0f,1.0f);
    glVertex3f(-1.0f,1.0f,-1.0f);            //Top Left
    glVertex3f(-1.0f,-1.0f,-1.0f);            //Bottom Left
    glVertex3f(-1.0f,1.0f,1.0f);            //Top Right
    glVertex3f(-1.0f,-1.0f,1.0f);            //Bottom Right

        //Top Facing
    glColor3f(0.5f,0.0f,1.0f);
    glVertex3f(-1.0f,1.0f,-1.0f);        //Top Left
    glVertex3f(1.0f,1.0f,-1.0f);        //Top Right
    glVertex3f(-1.0f,1.0f,1.0f);        //Bottom Left
    glVertex3f(1.0f,1.0f,1.0f);

    //Bottom Facing
    glColor3f(0.0f,0.5f,0.5f);
    glVertex3f(-1.0f,-1.0f,1.0f);        //Top Left
    glVertex3f(1.0f,-1.0f,1.0f);        //Top Right
    glVertex3f(-1.0f,-1.0f,-1.0f);        //Bottom Left
    glVertex3f(1.0f,-1.0f,-1.0f);        //Bottom Right
glEnd();                            // Done Drawing The Quad
rquad-=0.03f;
return TRUE;

}

Okay! Now I know where the problem is.

OpenGL draws vertices in clockwise and I was supposed to give it in a clockwise manner,(Top Left, Top Right, Bottom Right, Bottom Left).

:slight_smile:

So the modified code is


glBegin(GL_QUADS); // Draw A Cube
//Front Facing
glColor3f(1.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left
//Right Facing
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(1.0f,1.0f,1.0f); //Top Left
glVertex3f(1.0f,1.0f,-1.0f); //Top Right
glVertex3f(1.0f,-1.0f,-1.0f); //Bottom Right
glVertex3f(1.0f,-1.0f,1.0f); //Bottom Left
//Rear Facing
glColor3f(0.0f,1.0f,1.0f);
glVertex3f(1.0f,1.0f,-1.0f); //Top Left
glVertex3f(-1.0f,1.0f,-1.0f); //Top Right
glVertex3f(-1.0f,-1.0f,-1.0f); //Bottom Right
glVertex3f(1.0f,-1.0f,-1.0f); //Bottom Left
//Left Facing
glColor3f(1.0f,0.0f,1.0f);
glVertex3f(-1.0f,1.0f,-1.0f); //Top Left
glVertex3f(-1.0f,1.0f,1.0f); //Top Right
glVertex3f(-1.0f,-1.0f,1.0f); //Bottom Right
glVertex3f(-1.0f,-1.0f,-1.0f); //Bottom Left
//Top Facing
glColor3f(0.5f,0.0f,1.0f);
glVertex3f(-1.0f,1.0f,-1.0f); //Top Left
glVertex3f(1.0f,1.0f,-1.0f); //Top Right
glVertex3f(1.0f,1.0f,1.0f); //Bottom Right
glVertex3f(-1.0f,1.0f,1.0f); //Bottom Left

	//Bottom Facing
	glColor3f(0.0f,0.5f,0.5f);
	glVertex3f(-1.0f,-1.0f,1.0f);		//Top Left
	glVertex3f(1.0f,-1.0f,1.0f);		//Top Right
	glVertex3f(1.0f,-1.0f,-1.0f);		//Bottom Right
	glVertex3f(-1.0f,-1.0f,-1.0f);		//Bottom Left
	
glEnd();                

That is how GL_QUADS are drawn, vertex ordering varies by primitive type…