5

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.

debonair
  • 2,505
  • 4
  • 33
  • 73

1 Answers1

6

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.

Bartek Banachewicz
  • 38,596
  • 7
  • 91
  • 135
  • Thanks for your reply. I got your explanation about the matrix. But still i did not get " glDepthRange specifies a linear mapping of the normalized depth coordinates in this range to window depth coordinates" what does it mean? can you give a small example showing how glDepthRange works. – debonair Jan 07 '13 at 12:44
  • It's a complicated way to say that your compressed range (set by glDepthRange) is stretched into `(0,1)` :) (look again at the man - *window depth values are always treated as they are `(0,1)`*) I guess you might find it quite non-useful, but you shouldn't actually worry about it. – Bartek Banachewicz Jan 07 '13 at 12:54