Skip to main content
GameDev.net gamedev.net
🔒 Locked

Reading alpha with glReadPixels

Started by andy_fish Aug 8, 2003 at 1:58 PM 2 replies 4.3k views
Original Post
andy_fish
andy_fish
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.
Corrail
Corrail
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...
andy_fish
andy_fish
Yeah both the framebuffer and the call to glReadPixels use GL_RGBA
Corrail
Corrail
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...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.