Topmost Objects

Hello every body,
First of all let me explain what Iam trying to do.

Iam trying to use color buffers to store the objects names rather than the color. The reason is as follows:

If I use the convension technique of selection and picking, all objects that hit my boundaries will be returned as selected objects. Then I should filter them to know the top most of them according to their depth buffer value. In this technique objects that are completely overlapped by others may be included in the selected list even after filtering them. So, I tryed to use the names instead of colors in the statement
glColor3ub();
Ofcourse the color buffer is filled with colors of objects which are currently displayed on the screen. These colors actualy represent my objects names so I will scan the color buffer for the selected objects rather than the selbuffer[] which are returned from the selection process.
I will be very pleased if any one can help me.
M.Hassan (Mechanical Engineer)

Fine, and what’s your question?
(Did you search the board for “selection” methods?)

Hi Relic,
Iam very sorry for uncompleted topic. I have put my question on the (Begginer forums) and when I didn’t find any help I moved it to (advanced) and forget to edit it.
The problem is that when I separate the entity name into the three parts (Red, Green and Blue), the values of them got changed and I don’t know the reason even if I stopped lighting, dithering and stippling. Ofcourse the object names will be incorrect when retreiving them from the color buffer? Do you have any suggestion?
M.Hassan

No offense meant.
This will only work that way easily if you are using a 24 or 32 bit color resolution. (16 bit highcolor is a little trickier.)

Switching off lighting, dithering, stippling is the correct approach.
Check alpha blending, antialiasing, Gouraud shading, too. The objects need to be displayed in the pure color (materials don’t apply with lighting off, your picking name should be handled with the glColor3ub(v) call.)

Make sure there’s no conversion going on during the readback of the color data (no GL_FLOAT during ReadPixels).

glReadPixels(x,y,1,1,GL_RGB,GL_UNSIGNED_BYTE,pixels); should return the unfiltered RGB data containing the name.

Make sure the order of red, green, and blue is correct depending on your systems endianess or your conversion algorithm from name to RGB value.

Fit that with the byte ordering you get with either readback via GL_RGB(A) or GL_BGR(A)_EXT.

Make sure the glPixelStore is set correctly (GL_PACK_ALIGNMENT to 1?).