How can I efficiently perform selection in OpenGL?
I have read this question, and still some things remain uncertain to me.
In my application, I would like to support two forms of selection. First clicking with a mouse and second selecting using a pickbox. My application has also inherited a bunch of bad programming practices from the 90's and early 2000's specifically related to OpenGL, e.g., it uses GL_SELECT.
After all my reading, I understand this can be very inefficient. I have learned of two ways to address this:
- Color picking: assign a unique color to every object in the scene. Render it on a 1x1px imaginary window and read the color.
- Ray casting using collision detection
Questions:
- How do I perform color picking for a box? Do I simply render the scene on a window the size of my box and read the matrix of pixels collecting the unique colors to select appropriately?
- Is ray casting the preferred method? If so, how can this be extended for pick boxes?
- Is there another method other than these which is commonly used?