glReadPixels problem

hello,

i have a little problem with glReadPixels. Maybe someone can help me.

i have an int variable could color.
then i render a pixel by setting the color with
glColor3ub(color,color,color).
when i want to read out the color with
glReadPixels(x,y,1,1,GL_RGB,GL_UNSIGNED_BYTE,&select)
(select is defined as GLubyte) other values for red,green and blue then rendered are appearing.

thanks,
Poons

Hi,

The colors that get to the framebuffer are not necessarily the same colors you set with glColor. If you’re for example running in 16-bit mode, the color values get rounded to some nearby value. If you want to guarantee similar results, like for picking, use stencil buffer instead of colors.

-Ilkka

And note that glDrawBuffer and glReadBuffer can be set to different buffers.
Default for double buffering is GL_BACK for both, so if you readback after SwapBuffers, you don’t read the image you see but some (possibly undefined) stuff from the backbuffer.

Thanks a lot.

i´m now using the stencil buffer it works just fine.