How can I pick up objects in the screen?Only using glPushName()

Started by
2 comments, last by littlejedi 19 years, 2 months ago
I know OpenGL Select mode can be a method. But i need a lot of objects, and everytime i draw a object i need to repeat the same work(Switch mode between render and select, it's tiring). It costs a lot of memory. Is there another way? I heard of some gluUnproject()?But i can't know exactly how it works. Can someone tell me something about this? Thanks in advance
Advertisement
Well i don't know why using the gl picking would use a lot of memory.

There are countless ways for picking objects:

The unproject method you brought up does it mathematically. Knowing your cursors position you can project a ray out from your front clipping plane to your back clipping plane. Then with this ray you can intersect it mathematically with any objects. As for the objects, you can intersect with the actual polygons (slow) or use bounding sphere/box's.

I myself manually do picking similar to the way openGL does it, only for some reason it's much faster. I draw all my selectable items to the back buffer, with no lighting, textures or whatever, and color them depending on a ID number they are assigned. Then I do a glReadPixels for the one pixel the mouse is over at the time of selection. Then from the color it gets i figure out the ID.
There are several ways in which to use gluUnProject to get the 3D pick coordinates from mouse coordinates.

This article covers it, somewhat vaguely:

selection.

The easiest method is the second one they mention: Calling gluUnProject twice, first time with winz = 0.0, the second time with winz = 1.0. Of course, you'll also need to do your own intersection test between the objects and the picking ray, like skow said.

A simple ray - sphere intersection test is good enough for most things.
Thank you very much, and skow, could you show me some example code about the method of using different colors? Since I'm new with OpenGL, I don't know how to write the code.
Thanks!

This topic is closed to new replies.

Advertisement