Search code examples
c++qtopengltransparency

OpenGL transparent objects over background image


Due to the bad performance (high CPU usage) in my Qt3DOffscreenRenderer, which uses the Qt3D framework, I implemented a new offscreen renderer using only/mostly OpenGL.

Unfortunately, I can't get the object drawn on top of the background image to be transparent. I enabled blending and set glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);.

The result is the following:

enter image description here

What you can't see is that the Qt logo's pixels' alpha is 0.5.

For reference, this is the image without transparency:

enter image description here

I simply want the Qt logo to be a bit transparent, like so:

enter image description here

I managed to create this image using this example and modifing it to use the blend function mentioned above and an alpha value of 0.5 in the shader.

How can I achieve this for the offscreen renderer? I experimented with a lot of parameters but had no luck.


Solution

  • The problem was that I set the internal texture format of the QFramebufferObjectFormat to GL_RGBA32F but it needs to be GL_RGB32F (i.e. without the alpha channel).