Reading alpha with glReadPixels

Started by
2 comments, last by andy_fish 20 years, 8 months ago
Is there any way to read the alpha component of the framebuffer with glReadPixels? When I try, everything I read has an alpha of 1. What I want to do is be able to clear a certain area to have an alpha of 0, then draw to that area, then use glReadPixels to copy that area to a buffer, in such a way so that the pixels that I didn''t draw to still have an alpha of 0. Is this possible? Thanks.
Advertisement
Do you have defined an alhpa channel in your pixel format??

--------------------------------------------------------

"If it looks good, it is good computer graphics"
"If it looks like computer graphics, it is bad computer graphics"

Corrail
corrail@gmx.at
ICQ#59184081
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...
Yeah both the framebuffer and the call to glReadPixels use GL_RGBA
Yes, but did you set up an alpha channel (and the color channels) in your PIXELFORMATDESCRIPTOR like this:

PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER ,
PFD_TYPE_RGBA,
32, //Color Bits
8, // Bits for Red Channel
0, // ignored
8, // Bits for Green Channel
0, // ignored
8, // Bits for Blue Channel
0, // ignored
8, // Bits for Alpha Channel
0, // ignored
0,0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,
};

But be careful! If you use this with Descriptor with 32 Bits and run you application in windowed mode on a 16 Bit Desktop you recieve a software OpenGL context!! If Desktop has 16 Bits you have to design the Descriptor for 16 Bits too (16 Bit Color Bits, 4 Bits for each channel)

--------------------------------------------------------

"If it looks good, it is good computer graphics"
"If it looks like computer graphics, it is bad computer graphics"

Corrail
corrail@gmx.at
ICQ#59184081
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...

This topic is closed to new replies.

Advertisement