PDA

View Full Version : glReadPixels problem



Poons
01-22-2003, 11:52 PM
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

JustHanging
01-23-2003, 01:03 AM
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

Relic
01-23-2003, 07:21 AM
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.

Poons
01-23-2003, 11:25 PM
Thanks a lot.

im now using the stencil buffer it works just fine.