View Full Version : glReadPixels question

11-04-2004, 09:39 AM
I have a sphere and am looking from an arbitary position (using gluLookAt) at the surface of the sphere towards the center/origin of the sphere.

I need to transform screen co-ords into GL co-ords and gluUnProject is my answer.

However I do not understand how glReadPixels is used to return the winZ part of the screen co-ord.

How does glReadPixels know where the surface of my sphere is?
Is there some sort of depth testing going on that I need to set up first?

At the moment my viewport clipping planes surround the entire sphere so where is glReadPixels going to get the depth from?
Also it's a wire frame sphere so a click can go "right through" the sphere?!

I don't understand how winZ is determined - can someone please explain it to me in noob language?


11-05-2004, 11:46 AM

If I'm mistaken, disregard this response, but it sounds like your issue could be resolved with picking.

OpenGL has built-in functionality to determine what object is being drawn at a certain screen position.

Selection can actually get kind of complex, but in the simplest sense, you give ID numbers (GLuint's) to different parts of a scene, and render that information into a selection buffer which can be used to determine screen coordinates of objects.

The best advice may be to refer you to THE RED BOOK (Ch. 12) Selection and Feedback (http://fly.cc.fer.hr/~unreal/theredbook/chapter12.html)

Sorry I couldn't give a simple answer,