Sign in to follow this  

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

This topic is 4694 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

This topic is 4694 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this