Search code examples
c++qtopenglrenderingopengl-compat

QT OpenGL not fully rendering cube?


I am trying to create and display a 3D square but for some reason when I render it, parts of it are missing:

void DrawCube::drawCubes(int amount){ 



      glBegin(GL_POLYGON);
        glVertex3f( 1.0, -1.0,  1);
        glVertex3f( 1.0, -1.0, -1);
        glVertex3f( 1.0,  1.0, -1);
        glVertex3f( 1.0,  1.0,  1);
        glEnd();


      glBegin(GL_POLYGON);
        glVertex3f(-1.0, -1.0, -1);
        glVertex3f( 1.0, -1.0, -1);
        glVertex3f( 1.0,  1.0, -1);
        glVertex3f(-1.0,  1.0, -1);
      glEnd();


      glBegin(GL_POLYGON);
        glVertex3f(-1.0, -1.0, 1);
        glVertex3f( 1.0, -1.0, 1);
        glVertex3f( 1.0,  1.0, 1);
        glVertex3f(-1.0,  1.0, 1);
      glEnd();


      glBegin(GL_POLYGON);
        glVertex3f( -1.0, -1.0,  1);
        glVertex3f( -1.0, -1.0, -1);
        glVertex3f( -1.0,  1.0, -1);
        glVertex3f( -1.0,  1.0,  1);
      glEnd();
  }

}

rendering problem

I'm not looking for answers that just give me the code, but rather an explanation as to what causes this thanks.


Solution

  • The cube seems to be clipped by the far plane of the projection. Increase the distance to the far plane, when you set the projection matrix by glOrtho.
    Note, the projection matrix defines a view volume (see 3D projection). All the geometry which is out of the viewing volume is clipped.