This tutorial is about OpenGL picking. A scene made from cubes and spheres is created and rotated around the y-axis. The resulting GL 'picks' are sorted on the z-axis, thus the user is always able to select the front-most object at any time.
Picking with OpenGL ![](http://www.dev-gallery.com/programming/opengl/picking/intro.jpg)
This tutorial goes through OpenGL's picking (selection) capabilities. The selection buffer is used to return which objects are under the mouse pointer. These objects are then sorted in z-axis order to find which one (if more than one) is nearer to the 'screen'; a wireframe is then drawn 'on top' of the selected object to identify it. This z-axis sorting is very helpful, as it allows the user to select the nearest object to him from many overlapping objects. If for example, a chair was drawn in front of a wall, and the user clicked on the chair, OpenGL would return two hits; one from the chair and one from the wall, resulting in confusion. By sorting the GL hits related to their z-axis value (returned from OpenGL's picking functionality) the application 'knows' which object is nearer to the user and thus selects it. The tutorial is divided into two parts. The first part explains the creation of two simple classes DG_Vertex and DG_Object which will be used later in the main program. The second part contains the actual program which is made to demonstrate OpenGL's picking capabilities. Creating the DG_Vertex and DG_Object classes http://www.dev-gallery.com/programming/opengl/picking/picking2.htm
The main program & downloads http://www.dev-gallery.com/programming/opengl/picking/picking3.htm