Question

does depth clamp occurs before depth test or after depth test? I am rendering a primitive with coordinates > 1.0 and <-1.0 and using depth clamping with depth test. But when i enable depth test it does not render any geometry.

Here is my code:

GLfloat vertices[]=
    {
0.5f,0.5f,0.5f,                                   
-0.5f,0.5f,0.5f,
-0.5f,-0.5f,0.5f,
0.5f,-0.5f,0.5f,

0.5f,-0.5f,-0.5f,
-0.5f,-0.5f,-0.5f,
-0.5f,0.5f,-0.5f,
0.5f,0.5f,-0.5f  
}

for(int i=0;i<24;i++)
    vertices[3*i+2]*=25;

    glEnable(GL_DEPTH_CLAMP);

        // when i comment stmt below, it draws triangle strips
        glEnable(GL_DEPTH_TEST); 
        glClearDepth(15.0f);
        glClearColor (1.0, 0.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
        glDrawArrays(GL_TRIANGLE_STRIP,0,6);

How to use depth test and clamping together?

why does the above code does not draw anything on the screen with depth test enabled?

Was it helpful?

Solution

From OpenGL 4.3, 17.3.6:

If depth clamping (see section 13.5) is enabled, before the incoming fragment’s zw is compared, zw is clamped to the range [min(n; f ); max(n; f )]


i am assuming that by default it is GL_LEQUAL.

That's why you should post fully working examples when you don't know what's going on. The default depth test is GL_LESS. 1.0 is not less than 1.0, so all of your 0.5 depth vertices fail the depth test.

Also, your loop:

vertices[3*i+2]*=25

This is overwriting memory. Your index is going far off the end of the array, since it only has 24 elements. You probably meant to loop 8.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top