PDA

View Full Version : glReadPixels & alpha != 0



07-13-2004, 10:51 AM
Hi.
I have a texture with alpha=0
my glVlearColor = 0,0,0,0
So I make a glReadPixels and I have a pixel color = 0,0,0,1 !!!

How can I do to have the "real" pixels, which may be (0,0,0,0) ?

grimoire
07-13-2004, 01:58 PM
how are you reading it kind of like this
glReadPixels(0,0,100,100,GL_RGBA,GL_FLOAT,pixels)H ow are we supposed to know what's wrong if we don't know how you got the data. Maybe you didn't use GL_RGBA or you used GL_UNSIGNED_BYTE or something and some conversion happened.

07-13-2004, 02:34 PM
If I am not mistaken an alpha value of 1.0f or 0xff means completly opaque while 0.0f or 0x00 means completly transparent. Since it dosent make sence for the clear color to be transparent it will always be opaque not matter what you specify.

07-13-2004, 11:51 PM
I use:
glReadPixels(0,0,1,1,GL_RGBA,GL_FLOAT,*pixel)
and my clearcolor is (0,0,0,0).

SO the alpha value will always be opaque(=1) ?
SO, what is the interest to make a glreadPixel with GL_RGBA ?

Thanks

Bob
07-14-2004, 01:26 AM
The common mistake it to no request a destination alpha channel. Check how you set the pixel format. You want to write an alpha value to the frame buffer but there is no alpha channel, and the read back alpha is always 1 where there is no alpha channel.



If I am not mistaken an alpha value of 1.0f or 0xff means completly opaque while 0.0f or 0x00 means completly transparent. Since it dosent make sence for the clear color to be transparent it will always be opaque not matter what you specify.
What the alpha channel means depends on how you interpret and use it. It can mean transparency, yes, but it can also mean other things. You can use the destination alpha for lighting for example, and for transparency, you can even make alpha=1 mean totally transparent or opaque, depending on how the blending equation it setup. It makes perfect sense to be able to clear the destination alpha with an arbitrary value.