How to blit two transparent frame buffer objects using QOpenGLFramebufferObject?

873 Views Asked by At

I have two FBOs created using QOpenGLFrameBufferObject, which are images with a transparent background and some lines and text on top of them. I am blitting the first fbo onto the second using QOpenGLFramebufferObject::blitFramebuffer, this results in the content of the first fbo on top of the second. However, I would like to preserve the transparency of the the first fbo and blend the content of the first fbo on top of the second fbo (instead of erasing the portion of the second fbo and redrawing the first fbo on top of it). Looking around, I think this might be possible with glBlendFunc, but the following didn't really achieve the result I wanted.

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// then blit fbo1 on top of fbo2
QOpenGLFramebufferObject::blitFramebuffer(fbo2, fbo1);

How can I preserve the transparency (by blending them together) of my framebuffers when I blit them?

1

There are 1 best solutions below

0
Rabbid76 On

You can't glBlitFramebuffer is a copy operation, and does not blend the source and target fragments.
A possibility is to render to a texture (see Framebuffer Object - Attaching Images). Finally you can render a screen space rectangle and Blend the texture with the target framebuffer.