# Selection with region (when rendering with shaders and VAO)

I am currently render my geometry using "Modern OpenGL" approach (with shaders and buffers). I have already implemented picking of single primitives using glReadPixels. Now I am faced with problem how to implement selection of multiple objects. I cannot use glReadPixels because maximum (and it seems meaningful for me) number of objects that I could select with 10x10 box is 100. But it is really necessary for my purposes to have ability to select thousands of objects in small selection area.

I already read answer to similar question where was recommended to test each point against selection rectangle. But it gives new problems: all my vertices are already stored in buffers and it looks like huge performance to test each point on CPU.

Could someone help with such issue?

• What do you mean with "I have already implemented picking of single primitives using glReadPixels"? Are you using colorPicking? Is it acceptable for you get this selection only in top(side) view, or you need fully 3D selecting? – wondra Sep 10 '14 at 16:36
• Yes, I am using color picking. I also need fully 3D selection. Problem is color picking is not acceptable solution because I may have more then 100 elements on 1 pixel which need to be selected. – frankie Sep 10 '14 at 18:26
• Why is it limited to 100 elements? There is over 16mil colors. – wondra Sep 10 '14 at 19:03
• @wondra okay, but I guess that color picking would not work when there is to much elements at one square unit. – frankie Sep 11 '14 at 9:26
• you can always render the selected area in (much)higher resolution. Colorpicking cannot work if there are elements hiding behind each other and you want get all of them(picking regardless depth), in other cases, it will work with little tweaking. – wondra Sep 11 '14 at 12:25

## 1 Answer

One option is to take the screen coordinates for the rectangles corner points, convert them to rays in world space and then use these to define a box to do 3D collision detection with. The maximum length of the box should be the distance between the camera's near and far clipping plane.

• can you provide references where full approach is described, or post here some code? – frankie Sep 10 '14 at 11:47
• share please, how to perform selecting of objects with collision detection – frankie Sep 12 '14 at 8:48
• Collision detection is a big topic and is going to largely depend on your needs and any system you currently/plan to have, so I can't really outline it here. There are numerous ways to perform object picking with rays, and this method is simply an expansion to build a box from 4 rays instead. Looking up frustum culling may be useful to you here as well as it's similar. – OriginalDaemon Sep 12 '14 at 9:37