Fast and Dirty picking

Just wanted to bring up something I saw in an old post - an alternative picking method. For me, it is perfect

Just give each object in your scene a different rgb color, and draw to the backbuffer without swapping (so the user never sees your rainbow scene).
Then get the rgp color of the pixel the user clicked on (from the back buffer of course)
and you can go backwards to which object it was. This automatically gives you the object on top.
And of course you can speed it up by only drawing the selectable objects.

I’d be interested in knowing if this method is faster than using the opengl selection mode stuff. It certianly seems easier to code, maybe theres other drawbacks? You can only select the top object maybe thats it

Another interresting idea I’ve been playing with (for selection) is to use gluProject to project the exact center of each object onto the viewing plane (neatly transforms into x,y screen coordinates), and then using scaling to scale an approximate bounding box around each object.

I think it is a bit faster than rendering some parts of the scene twice, associating colors etc., the drawback though being that bounding boxes aren’t all that accurate.

Sounds like that would work too. I guess it all depends on what types of things you have that are selectable, and how many.

For me, most of my scene is trees and ground, which I don’t have to draw to select by color. Also, you only have to do this when the mouse is actually clicked.

Well anyway just wanted to see what other ideas are out there Most of the picking threads on here all use the same basic idea, I suppose because it works and is in hardware. Still, I think it can be overkill depending on what you need.

BUT - what if two poly’s share the same coords in one plane? How could you select something that is obscured by another poly? - you cant!

The method you are talking about only works if you never have to select a poly that is further away. Therefore it only works in simple cases