Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

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

  1. #1
    Newbie Newbie
    Join Date
    May 2013
    Posts
    2

    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;
    }

    Last edited by dorbie; 05-11-2013 at 11:06 PM. Reason: added image link at users request

  2. #2
    Newbie Newbie
    Join Date
    May 2013
    Posts
    2
    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).



    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();
    ......
    Last edited by anupchowdary; 05-11-2013 at 03:02 PM. Reason: further explanation

  3. #3
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,946
    That is how GL_QUADS are drawn, vertex ordering varies by primitive type...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •