opengl - glDepthRange 是如何工作的?

标签 opengl depth depth-buffer depth-testing

我的顶点线是:

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     

    };

现在,我正在通过以下方式更改 z 线:
for(int i=0;i<24;i++)
    vertices[i*3+2]*=10
glDepthRange(0,10.0);

现在,我期望由于 glDepthRange 调用,z 线将被映射到 -0.5 到 0.5 范围,我可以看到一个合适的立方体,但它给出的 o/p 与我在上面用扭曲的几何体评论 glDepthRange 调用时一样。

最佳答案

让我给你引用手册页:

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.



突出显示我的

换句话说,您不能真正使用大于 1 的深度值;你必须自己正确计算它们,而不是。它基本上总结为设置适当的 nearfar投影矩阵中的值并转换 Modelview 矩阵中的 Z 坐标,以便所有最终 Z 都在上述值之间。

如果您需要更详细的解释,请发表评论。

关于opengl - glDepthRange 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14195857/

相关文章:

java - LWJGL:无法在 opengl 中渲染多个形状

c++ - 在具有专有 Nvidia 驱动程序的 Linux 上,多个 OpenGLX 渲染上下文失败

python - 将字典列表转换为层次结构

opencv - 针孔相机如何感知深度?

r - 使用 ggplot 绘制深度剖面

ios - OpenGLES 2.0 错误的深度缓冲位

opengl - 为什么 OpenGL + GLSL 着色器不输出任何内容?

c++ - 保存数据以便从体素编辑器中重新使用的最佳方式

c++ - 使用深度测试正确渲染 OpenGL 中的表面

java - Java中的深度缓冲和多边形填充