How can i pick items by using glReadPixels ?
Is any other way to pick except glupickMatrix ?
-
disable lighting and texturing, enable depth test.
-
draw all elements in the back buffer,
giving each element a unique color.using 24-bit color mode makes it easier to encode
the element into a color value.red = element_id & 0xff;
green = (element_id / 256) & 0xff;
blue = (element_id / 65536) & 0xff;glColor3ub(red, green, blue);
do NOT use the float/short/int version of glColor,
because the red/green/blue values may be internally rounded. -
use glFlush, do NOT swap buffers. read the back buffer at pointer position.
the color value tells you which element you
clicked on.assuming you read the pixel color into a field col[3] you get the element id
element_id = col[0]&0xff + 256*(col[1]&0xff) + 65536*(col[2]&0xff);