Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does glDepthRange work?

My vertex cords are :

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,//face 1

        0.5f,-0.5f,-0.5f,
        -0.5f,-0.5f,-0.5f,
        -0.5f,0.5f,-0.5f,
        0.5f,0.5f,-0.5f,//face 2

        0.5f,0.5f,0.5f,
        0.5f,-0.5f,0.5f,
        0.5f,-0.5f,-0.5f,
        0.5f,0.5f,-0.5f,//face 3                

        -0.5f,0.5f,0.5f,
        -0.5f,0.5f,-0.5f,
        -0.5f,-0.5f,-0.5f,
        -0.5f,-0.5f,0.5f,//face 4

        0.5f,0.5f,0.5f,
        0.5f,0.5f,-0.5f,
        -0.5f,0.5f,-0.5f,
        -0.5f,0.5f,0.5f,//face 5

        -0.5f,-0.5f,0.5f,
        -0.5f,-0.5f,-0.5f,
        0.5f,-0.5f,-0.5f,
        0.5f,-0.5f,0.5f//face 6     

    };

now, i am changing z cords by:

for(int i=0;i<24;i++)
    vertices[i*3+2]*=10
glDepthRange(0,10.0);

Now, i am expecting that z cords will be mapped to -0.5 to 0.5 range due to glDepthRange call and i can see a proper cube, but it gives o/p as that of when i comment glDepthRange call above with distorted geometry.

like image 585
debonair Avatar asked Jan 07 '13 12:01

debonair


People also ask

How does depth test work?

Depth test function The depth test never passes. Passes if the fragment's depth value is less than the stored depth value. Passes if the fragment's depth value is equal to the stored depth value. Passes if the fragment's depth value is less than or equal to the stored depth value.

How is depth buffer calculated?

z' = (2^d -1 ) * ((far + near)/(2 * (far - near) + (1 / z) * (-far * near) / (far - near) + 1/2) when d is the depth of the z-buffer (24 bits at my case) and z is the z value of the vertex.

What is depth testing in computer graphics?

Depth Testing is a testing technique in which feature of a product is tested in full detail. Each of the feature is tested exhaustively during the integration phase and the defects are logged, are captured across all parameters, functional and non functional.


1 Answers

Let me cite you the man pages:

After clipping and division by w, depth coordinates range from -1 to 1, corresponding to the near and far clipping planes. glDepthRange specifies a linear mapping of the normalized depth coordinates in this range to window depth coordinates. Regardless of the actual depth buffer implementation, window coordinate depth values are treated as though they range from 0 through 1 (like color components). Thus, the values accepted by glDepthRange are both clamped to this range before they are accepted.

highlights mine

In other words, you can't really use depth values greater than 1; you have to calculate them properly by yourself, instead. It essentially concludes to setting appropriate near and far values in your Projection Matrix and translating Z coordinate in your Modelview Matrix, so that all final Zs are between the aforementioned.

Please leave a comment if you need more detailed explanation.

like image 198
Bartek Banachewicz Avatar answered Oct 09 '22 10:10

Bartek Banachewicz