Home Ask Login Register

Developers Planet

Your answer is one click away!

x6herbius February 2016

Qt OpenGL - Translucent objects show content from behind window

I'm using Qt5 and its OpenGL integration, and am running into a problem when I try to draw translucent objects. When an object is translucent, whatever is visible behind my OpenGL window is shown within the screen area of that object, instead of the object being blended with whatever is already in the colour buffer. I have started watching YouTube videos through my translucent objects, as whatever shows through is live.

Translucency

Interestingly, the most see-through an object gets seems to occur at half opacity - full opacity renders it solid, while zero opacity renders nothing at all (and whatever was previously in the background of the 3D scene remains there). Rendering translucent objects last does not fix the issue.

I have noticed that this also happens when I enable mipmaps on my textures - as the distance to a point on an object increases, the pixel concerned becomes more translucent and displays whatever is behind the OpenGL window. The issue occurs both on my Windows and OSX machines.

Is this a known issue? Is there a workaround? Google hasn't proven too helpful.

Answers


datenwolf February 2016

Hah, that's a funny one. I can't tell you what is going on, because it normally takes some extra effort to make windows actually transparent; in Windows you have to select a framebuffer format with an alpha channel and call DwnEnableBlurBehindWindow to actually achieve this effect. And as far as I know Qt doesn't do this.

But if it does here are a few hints:

  • Make sure you clear your framebuffer to alpha=1
  • When rendering translucent objects keep the destination alpha value 1, i.e. don't use blending modes and functions that modify the destination alpha value, or force it to 1.

There's actually little use for the alpha channel on the main window framebuffer, except for implementing window translucency effects. Unless you need those you should choose an either pixel format without an alpha channel for your window framebuffer, or keep all its pixels alpha values at full opacity.

Post Status

Asked in February 2016
Viewed 2,889 times
Voted 13
Answered 1 times

Search




Leave an answer


Quote of the day: live life