Search code examples
c++openglopengl-compat

opengl glDepthRange object disappearing on Z depth


enter image description here Lines are dissapearing when z depth increases while rotating the object around x axis by 10 degrees. I edited the glDepthRange value to -100,100 or higher but nothing changes. How can i solve this?

void render()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    if( gRenderQuad )
    {
        glBegin( GL_LINE_LOOP );
        glVertex3f(0.3f, 0.5f, 0.4f );
        glVertex2f( -0.5f, -0.9f );
        glVertex2f( 0.5f, -0.5f );
        glVertex2f( 0.5f, 0.5f );
        glVertex2f( -0.5f, 0.5f );
        glEnd();
    }
    glDepthRange(-100,100);
    glEnable(GL_DEPTH_TEST);

}

enter image description here


Solution

  • I edited the glDepthRange value to -100, 100

    This is not possible. The values for the depth range must be in [0.0, 1.0]. You can just set a sub range of the range [0.0, 1.0]. See glDepthRange.

    If you want to increase the viewing volume, you need to use a projection matrix. An Orthographic projection can be set with glOrtho:

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-1.0, 1.0, -1.0, 1.0, -100.0, 100.0);
    glMatrixMode(GL_MODELVIEW);