gpt4 book ai didi

opengl - glDepthRange 是如何工作的?

转载 作者:行者123 更新时间:2023-12-05 00:31:51 29 4
gpt4 key购买 nike

我的顶点线是:

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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com