Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set the background of a QQuickFramebufferObject to transparent?

Tags:

c++

qt

opengl

qml

I am using QQuickFramebufferObject in QML to draw OpenGL code. I've found a couple ways to do OpenGL with QML, one of which (in Qt's Squircle example) is to draw all OpenGL either below everything or above everything, but I'm using the QQuickFramebufferObject method because I need regular QML objects both above and below the OpenGL-drawn object.

All the OpenGL code works fine. The background of the QQuickFramebufferObject needs to be transparent so that the QML objects underneath can be seen. (My QQuickFramebufferObject draws an abstract shape.) However, QQuickFramebufferObject seems to block out its rectangle on the screen and not show anything underneath. I have tried

glClearColor( 0.0, 0.0, 0.0, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );

so that the background is transparent, but instead I just get a white rectangle. Even if I skip calling the FBO's render altogether, it still draws over everything, so I think it's something outside the OpenGL code and how QML handles the FBO.

What I want:

What I want

What I get:

enter image description here

like image 619
user3735151 Avatar asked Oct 31 '22 11:10

user3735151


1 Answers

I figured it out, it was a mistake not with the FBO, but the Rectangle holding it. I never set its color, since I'm only using it as a holder for other objects, which seems to be by default white, not transparent. I changed it to be color: "transparent" and now all is well.

like image 171
user3735151 Avatar answered Nov 05 '22 12:11

user3735151