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?

  • \$\begingroup\$ 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? \$\endgroup\$
    – wondra
    Commented Sep 10, 2014 at 16:36
  • \$\begingroup\$ 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. \$\endgroup\$
    – frankie
    Commented Sep 10, 2014 at 18:26
  • \$\begingroup\$ Why is it limited to 100 elements? There is over 16mil colors. \$\endgroup\$
    – wondra
    Commented Sep 10, 2014 at 19:03
  • \$\begingroup\$ @wondra okay, but I guess that color picking would not work when there is to much elements at one square unit. \$\endgroup\$
    – frankie
    Commented Sep 11, 2014 at 9:26
  • \$\begingroup\$ 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. \$\endgroup\$
    – wondra
    Commented Sep 11, 2014 at 12:25

1 Answer 1


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.

  • \$\begingroup\$ can you provide references where full approach is described, or post here some code? \$\endgroup\$
    – frankie
    Commented Sep 10, 2014 at 11:47
  • \$\begingroup\$ share please, how to perform selecting of objects with collision detection \$\endgroup\$
    – frankie
    Commented Sep 12, 2014 at 8:48
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Sep 12, 2014 at 9:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .