View Full Version : OpengGL 4 + select

05-07-2013, 07:27 AM

I'm new in this forum, and I'm starting with opengl4. My doubt is about object selection/moving.

I read some documents about selecting objects in an scene (ray tracing, GL_SELECT, color picking, etc..)
However, since GL_SELECT has been deprecated, which is the adequate method for selecting/moving objects in the scene? (assume a simple scenario with a simple cube).

Thank you very much

05-07-2013, 06:11 PM
(assume a simple scenario with a simple cube
gluUnProject should work for this; I don't like it when the scene gets more complex.

06-17-2013, 12:23 PM
I'm really sorry for the delay, I've been busy with exams.

The gluUnproject is for color picking isn't it? (assuming simple scenes)
When the scene get more complex, which method will you use?

06-17-2013, 02:46 PM
The gluUnproject is for color picking isn't it?
gluUnProject simply concatenates the matrices, inverts the result, then transforms the specified point. It's used for converting screen coordinates to object coordinates, e.g. if you're going to be performing picking in the application code. Or rather, it used to be; with modern OpenGL, you generate your own matrices, so there's no reason to get OpenGL involved.

When the scene get more complex, which method will you use?
The "modern" alternative to select and feedback modes is transform-feedback (which is more like feedback mode than select mode). This lets you capture the output after vertex and geometry shaders (and culling).

The way to implement something like selection would be to add an integer vertex attribute for the object ID, have the vertex/geometry shader output this as a "flat" variable, and use transform-feedback to capture this variable. If you need hierarchical "names", you would need to implement this in the application, allocating integer IDs and storing the mapping from IDs to names.

An alternative would be to add another colour buffer to which the object ID would be written, and use glReadPixels() to read a single pixel from the buffer to obtain the object ID under the cursor. This may be preferable if the window isn't being continually refreshed and you want to implement "mouseover". Programs using OpenGL 1.x often did something similar by rendering the scene with object IDs mapped to colours, but support for integer framebuffers makes this more robust (the colour approach would often fail on systems with limited colour depth).