PDA

View Full Version : read the depth buffer



snupinokio
07-05-2003, 11:22 PM
How can I read the z coordinate value from the z buffer, for a given x & y coordinates?

Requiered for a program where the user selects a 3D object (in perspective presentation) using the mouse's cursor.
Thanks

Rog
07-05-2003, 11:42 PM
In a Windows app, I do something like this -


float fWinZ;
int nViewport[4];
glGetIntegerv(GL_VIEWPORT, nViewport);

// reverse y coordinate for windows
int y = nViewport[3] - y - 1;
glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &fWinZ);


Any good? http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by Rog (edited 07-06-2003).]

snupinokio
07-17-2003, 10:32 PM
Thanks, i will check this.

I have a new problem:
I have a program that receives from the user control points of two B-Spline curves (de Boor points) and draws the surface with these curves as edges, connecting in a straight line between each two control points in different curves (ruled surface).
My problem is the gluNurbsSurface method doesn't work correctly when the control points array is dynamically allocated (two or three dimentions array), where it works correctly when it is statically allocated. i didn't find how to operate it right.

I would be grateful for any help anyone can give me with this.
Thanks



Originally posted by Rog:
In a Windows app, I do something like this -


float fWinZ;
int nViewport[4];
glGetIntegerv(GL_VIEWPORT, nViewport);

// reverse y coordinate for windows
int y = nViewport[3] - y - 1;
glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &fWinZ);


Any good? http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by Rog (edited 07-06-2003).]