An alternative method for locating objects is to write integer object names as color values into the framebuffer and read back the framebuffer data within the pick region to reconstruct the object names. In order for this to work correctly, the application needs to be able to predictably write and read color values. Texturing, blending, dithering, lighting and smooth shading should be disabled so that fragment color values are not altered during rasterization or fragment processing. The unsigned integer forms of the color commands (glColor3ub(), etc) should be used to pass in the object names, as the unsigned forms are specified to convert the values in such a way as to preserve the b most significant bits of the color value, where bis the number of bits in the color buffer. To limit selection to visible surfaces, depth testing should be enabled. The back color buffer can be used for the drawing operations to keep the drawing operations invisible to the user.
A typical RGB color buffer storing 8-bit components can represent 24-bit object names. However, since the color must uniquely identify the object, instancing information must be available directly in the color. That is, the functionality provided by the name stack in the OpenGL selection mechanism is not available, so the application may need to partition the representable name space to hold hierarchy information. For example a 4 level hierarchy can be allocated a 24-bit color as 4,4,6 and 10 bits allowing more object names for leaf parts of the hierarchy.
One disadvantage of using the color buffer is that the color buffer can only hold a single identifier at each pixel. If depth buffering is used, then the pixel will hold the object name corresponding to a visible surface. If depth buffering is not used, then a pixel hold the name of the last surface drawn. The OpenGL selection mechanism can return a hit record for all objects that intersect a given region. The application is free to choose one of the intersecting objects using a separate policy, e.g. the object closest to the viewer, iterate through all of the objects one at a time, etc.