View Full Version : FBO and alpha channel
11-02-2005, 03:03 PM
Hi, i'd like to save current screen to a texture generating an alpha channel.
To make it simple, just figure out you have a scene with a black background and a textured teapot.
Is it possible to render to a texture (using FBO's) where the alpha channel is black for any black pixel of the main scene, and white for any pixel with color >0 ?
Hope this make sense ...
11-02-2005, 03:21 PM
Maybe there is something I don't understand, but if you set the clear color to (r, g, b, 0) and you render sthg which isn't transparent like your textured teapot (alpha = 1.0 or 255), then you obtain what you want directly. If i misunderstood your problem, you should explain a little more what you want to do. Or is your problem related to FBO?
11-03-2005, 02:26 AM
I believe OP want every incoming black fragment to result in transparency in the target RGBA texture, and all other fragments to result in an opaque alpha value. Basically color-keying resulting in a binary (on/off) alpha result.
With the number of possible definitions of "current screen" I think that needs clarification. Perhaps "framebuffer" is intended?
11-03-2005, 03:09 AM
Well, after more testing, it is just a problem of blending, but i can't figure out the right one. The FBO it's ok, it generates a RGB texture (see this (http://www.flightzone.us/shot1.jpg) screenshot).
Later on, i apply this texture using glBlendFunc(GL_SRC_COLOR,GL_ONE) , but as you can see from this (http://www.flightzone.us/shot2.jpg) screenshot, blending is not correct: only area in front of the teapot are blended nicely.
I suppose it's just a matter of setting the correct blend function ?
thanks for any suggestion
11-03-2005, 03:30 AM
tamlin, that's exactly what i intended to do. You explained much better than me.
For current screen i meant the frame buffer.
Are you generating a RGB or a RGBA texture? For this particular example (monochrome cloud texture) I would suggest using a solid white texture with one colorchannel of the cloud as the alpha channel.
Then use GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA as blendmode.
For better results render the cloud onto a medium grey background and also read out the alpha from your FBO, same blending.
11-04-2005, 04:39 AM
Thanks def, that make sense. But after reading the fbo extension specs, couldn't find how to write separately rgb and alpha channels.
I am sure there are alpha values involved in generating the cloud texture, no?
Just setup a FBO with alpha bitplanes and use a RGBA texture. Then just alter your "cloud render code" to what you need in the texture, including the alpha channel. (I haven't gotten around to using FBOs myself, though... ) :rolleyes:
In OpenGL, whatever you are drawing alpha values are also stored in (not visible) bitplanes (but only if the right pixelformat was specified when creating your target buffer). This should work for the standard framebuffer aswell as FBOs. Just concider it an additional color channel.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.