高分!!glReadPixels函数读深度缓冲为啥全是1

来源:百度知道 编辑:UC知道 时间:2024/06/06 19:17:47
我用的是双缓冲,GL_MODELVIEW下,开启深度测试,划了一些点和线(坐标是GL_float型有正有负),交换缓冲后,glReadPixels(0,0,width,height,GL_DEPTH_COMPONENT,GL_FLOAT,z),结果全是1,请高手解答。
如果我想读屏幕上点的实际深度值,该怎么办? 我是想根据深度值判断点有没有被遮挡,但是得先读出来。

GL_DEPTH_COMPONENT -- 读到的是“深度”值,相当于RGBA里的A,(GL_ALPHA) . 结果可能就是1。
ALPHA 用来模拟 “雾”,半透明。 画图时用到不同的ALPHA,读深度才能读出0-〉1 间的数值。
坐标正负与ALPHA并无直接关系。
读的区域是[0,0]到[width,height]
-------------------------------------------------------
GL_DEPTH_COMPONENT
Depth values are read from the depth buffer. Each component is converted to floating point such that the minimum depth value maps to 0 and the maximum value maps to 1. Each component is then multiplied by GL_DEPTH_SCALE, added to GL_DEPTH_BIAS, and finally clamped to the range 01.

GL_DEPTH_COMPONENT -- 读到的是“深度”值,相当于RGBA里的A,(GL_ALPHA) . 结果可能就是1。
ALPHA 用来模拟 “雾”,半透明。 画图时用到不同的ALPHA,读深度才能读出0-〉1 间的数值。
坐标正负与ALPHA并无直接关系。
读的区域是[0,0]到[width,height]
-------------------------------------------------------
GL_DEPTH_COMPONENT
Depth values are read from the depth buffer. Each component is converted to floating point such that the minimum depth value maps to 0 and the maximum value maps to 1. Each