1

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?

debonair
  • 2,505
  • 4
  • 33
  • 73

1 Answers1

4

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • why it does not draw anything on the screen? – debonair Jan 15 '13 at 07:04
  • 2
    That's a completely different question from what the order of clamping vs. testing is. And answering it will require a lot more than what you posted. Things like what your depth test is, the matrices you're using, etc. – Nicol Bolas Jan 15 '13 at 07:14
  • i am not using any matrices at all, just passing above vertices array in shader. About depth_test, as i am not calling any other API for depth comparison, i am assuming that by default it is GL_LEQUAL. – debonair Jan 15 '13 at 07:35
  • 1
    @Roshan: Of course you're using a matrix, even if it's just the identity matrix, which can be written in a number of ways. If you're using a shader, then you *must* post the shader source, so that we can make any valuable suggestions, as without the shader we're in the blind. – datenwolf Jan 15 '13 at 11:02