I have two scenes:

A:



B:



I want A to serve as a background scene, and B to serve as a foreground scene, so I do this:

* clear depth buffer
* clear color buffer
* render A
* clear depth buffer
* render B

And that works as expected:



But now, instead of rendering everything directly into the default buffer, I want to render B into a FBO first, and then render the FBO into the default buffer. So I did this:

* clear depth buffer
* clear color buffer
* render A
* clear depth buffer
* render B to FBO
* render FBO

However, that produces a different result:



I did some research as to why this is happening, and it seems that the blend function I'm using (typical GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) is not only blending the colors, but the alpha value as well, and following the math:

Code :
(sA*sA) + (dA*(1-sA)) = rA  ---> (0.8*0.8) + (1.0*(1.0-0.8)) = 0.84

So, that's < 1, and I guess that's why the background is "leaking" when rendering the FBO into the default buffer.

But, why does it work fine when rendering directly into the default buffer? Why doesn't that leak in the same way?

I would like to use the FBO, but get the same blending that I would when rendering directly. Is there a way to do that?