Transparencies when drawing an FBO in an FBO

Hello, I’m developing a graphics program on OpenFrameworks, and I’m having issues with transparencies.

According to this, if you want to draw an FBO with transparencies on the screen, you must write this:

void draw ()
   // draw image on FBO

   textureFbo.begin ();  
   ofEnableAlphaBlending ();  
   image.draw (0, 0);  
   ofDisableAlphaBlending ();  
   textureFbo.end ();

   // draw FBO on screen

   glEnable (GL_BLEND);  
   textureFbo.draw (0,0);  
   glDisable (GL_BLEND);

However, that code isn’t working to me. The poster said: “You have to draw the fbo with a different blending mode than when you are drawing to the fbo.”

But I’m drawing videos on an FBO, then draw them on another FBO, and then draw them on an ofxGLWarper. So I’m trying to do both things at the same time!

void draw ()
    // draw videos on a scene FBO
    sceneFbo->begin ();
    drawVideos ();
    sceneFbo->end ();
    // draw the scene FBO on a second FBO
    alphaFbo->begin ();
    sceneFbo->draw (0, 0);
    alphaFbo->end ();
    // draw the second FBO on a quad
    quad->begin ();
    alphaFbo->draw (0, 0);
    quad->end ();

Actually it’s even more complicated. I don’t just draw videos in the scene, but also more FBOs. And the alphaFbo may use an alpha mask with setUniformTexture().

So I’m trying different combinations of glEnable, glBlendFunc and glEnableAlphaBlending but they don’t work.

Any suggestions on how to draw an FBO in an FBO with transparencies? Or where can I learn about blending functions? Thanks!

I would take a look at ofClearAlpha() which clears the alpha channel. When you draw something with alpha, you not only (potentially) draw in the color channels you also alter the alpha channel, so alot of times with fbos you get results you don’t expect (because you don’t think of the alpha passing through). ofClearAlpha() is useful – I sometimes do:


It seems to have solved ths issue. Thanks! :slight_smile: