# 3D coordinates of a pixel

Hi,

I have to know the 3D coordinates of each pixel of a scene.
Is there a simple way to do it ? I mean, not by raytracing

thanks for your help…

I only started looking at OpenGL for the first time yesterday so I’m not quite sure but I read about a function called gluUnProject() in the red book.

http://www.mevis.de/~uwe/opengl/gluUnProject.html

Hope it helps

yeah thanks but i need to have all the coordinates that are visible. I mean, if an object is semi transparent and i can see another object behind, i need also the 3D coordinates of this object behind…
this function will need the depth of this object behind to return the 3D coordinates. But i don’t have this one…
or maybe can I reach multiple depth if there is transparencies in my scene ???
glReadPixel can give me multiple values for the same pixel ??

Transparency is a problem. I am not sure what your application is, so I am not sure if you are going about this in the best way. However, if you neglect cases where there are two transparent surfaces overlaping eachother, you might be able to get away with drawing just the opaque surfaces, then getting the coordinates you want, then drawing the transparent surfaces.

Once a translucent object is drawn, no information is available in the depth buffer about the distance of the object it covers. (This is why you need to depth-sort translucent polygons.)

even with depth sorting, you’ll find that you run into problems in the case of intersecting polygons.

after all, what is the depth of a polygon? it’s nearest vertex…it’s farthest vertex…an interpolated center point?
However, endash’s suggestion is not a bad one.

glReadPixel can give me multiple values for the same pixel ??

glReadPixels does nothing but copy the contents of the video memory into system memory. It will tell you nothing of the depth values of those pixels.

Not quiet right. You can readout the entire content of the z buffer by using:

``````
glReadPixels(0,0,width,heigth, GL_DEPTH_COMPONENT, GL_FLOAT, ptrToMyDestMemory);
``````

Of course these z values are projected and range between 0.0f and 1.0f in a non-linear fashion. You still have to unproject them but its not guaranteed that you will get the exact z value back due to the limited z buffer accuracy.