2012-10-06 12 views
1

我用过剩来显示我的3D场景函数读取深度数据的含义是什么:glReadPixels的过剩?

glReadPixels(300,//xPos 
      300,//yPos 
      1,1,//size 
      GL_DEPTH_COMPONENT,//type is depth 
      GL_FLOAT,//return type is float 
      &point); 

我想用这个功能来获得一个像素的深度。 但返回的数据总是在范围[0,1],如0.999872, 0.999921..... 我怎样才能将其转换为真正的深度(从对象到摄像头)

+1

glReadPixels是OpenGL的一部分,而不是GLUT。 – datenwolf

回答

0

我想用这个函数可以获得像素的深度。但返回的数据总是在范围[0,1],如0.999872,0.999921 .....

这些值在glDepthRange设置的范围内。默认值是[0,1]。

我怎样才能将其转换为真正的深度(从对象到摄像头)

通过投影屏幕空间坐标(你有什么)回到世界空间。您可以使用gluUnProject。它接受的model矩阵取决于你想要ptoject的空间。 OpenGL没有相机,所以这一切都取决于您定义的查看矩阵。你没有显示你的绘图代码,所以我不能告诉你在哪一点上拿一个模型视图矩阵的副本来保存你需要的视图矩阵。

0

glReadPixels手册:

    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 [0, 1] 
相关问题