View Full Version : [HELP] Drawing with ALPHA channel on FBO ?

07-03-2009, 04:28 AM
I am trying to create an FBO, draw to it on the alpha channel and then apply the FBO to the main buffer.
Basically I have a video stream being played on the main buffer and I want to create some overlays to display on top of it.
I have a library to create and initialize the FBO... the texture it creates has an RGBA flag set:

glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
and the whole program has
The images I am trying to load on the FBO are PNG with an alpha.

The result so far is that when I run the program the FBO has the various PNGs but also a black background (due the glClear) that enterely covers what's behind. If I use glBlendFunc(GL_ONE, GL_ONE) while drawing on the FBO then when I render it on top of the main FBO it works fine... but I dont like the adding mode.

Could someone explain me how to correctly draw on a FBO using the alpha channel to mask only the drawn regions?

07-03-2009, 05:03 AM

07-03-2009, 06:39 AM
it still renders the PNGs with a black background that covers what's behind...
glBlendFunc(GL_ONE, GL_ONE); works quite fine because it multiplies the FBO with the main buffer and since the FBO background is black the effect on the main buffer once multiplied in none... but the colours on the FBO when multiplied over the main buffer are slightly changed.

What's the way to draw an FBO (texture2D) on top of the main buffer using its alpha channel?
How can I make sure that the alpha channel of my FBO actually retains the alpha from the loaded PNGs?
Is there a way to directly draw on the alpha channel?

Many thanks,

07-03-2009, 08:33 AM
hem, I am not sure to understand the interest of using a fbo here. Could you detail clearly each step of the rendering?

To draw an overlaying picture on top of the current rendering like a hud, you just need to:

- load the png file in a texture
- set up blending
- draw a quad in orthographic projection with the texture mapped on it.

No fbo in this case. It would be needed if you are generating the texture procedurally or applying some post-processing effects on it.

07-03-2009, 08:46 AM
As dletozeun said... you just need to draw a 2D quad on your main GL window using fixed funcitionality. Enable BLEND and use GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA as the blendfunc paramaters. When you are about to render the HUD/overlay, set the projection matrix, disable depth testing and just set the transparency with a glcolor4f command:

glcolor4f (1,1,1, 0.5) //partially blend the overlay.