Last 2 weeks I started working on a box selection that selects shapes using GL_SELECT and I just got it working finally.
When looking up resources online, there is a significant number of posts that say GL_SELECT is deprecated in OpenGL 3.0, but there is no mention of what had replace that function.
I learnt OpenGL 1.2 in back in college 2 years back but checking wikipedia now, I realise we already have OpenGL 4.0 but I am unaware of what I need to do to keep myself up to date.
So, in the meantime, what would be the latest preferred method for box selection?
EDIT: I found http://www.khronos.org/files/opengl-quick-reference-card.pdf on page 5 this card still lists glRenderMode(GL_SELECT) as part of the OpenGL 3.2 reference.
Answer
The way I do picking in core OpenGL is to assign a unique color to every object in the world and draw only the vertices (no texcoords, normals, etc.) with the assigned color to a FBO.
Once all the objects have been drawn, you can call glReadPixels at the mouse coordinate with a width and height of 1 to get the pixel color at that point. Then all you have to do is lookup which object was assigned to that color and return it.
If you want to drag-select a rectangle, do the same thing, but store the pressed mouse coordinate and change the parameters of glReadPixels to read back the selected rectangle between the pressed mouse coordinate and the released mouse coordinate.
No comments:
Post a Comment