I'm using Qt 5.4, QtQuick 2.4.
Basically, I'd like to be able to render raw OpenGL into an application written in QtQuick/QML, and I would like to do so while using QQmlApplicationEngine
.
The main tutorial I have gone through is the (seemingly) pretty standard one, found here.
However, this tutorial uses a QQuickView
rather than a QQmlApplicationEngine
to load the QML UI. If I change the code to use a QQmlApplicationEngine
, the GL rendering no longer works, and I really don't understand why.
The code in this GitHub repository promises to draw raw OpenGL into a QtQuick application using QQmlApplicationEngine, and even manages to keep this promise, but it does so by hooking into QQuickWindow::afterRendering
(see line 79 of squircle.cpp
). If this signal/slot connection is changed to hook into QQuickQindow::beforeRendering
, the GL portion of the scene again appears unrendered. This is IMO the simplest example that reproduces the issue I am having (except for some boilerplate hanging around).
QQuickWindow::clearBeforeRendering
appears to (correctly) be set to false (line 86 of the same file).
Am I missing something?
In Qt 5.4 the Window.contentItem
property was introduced and painting of ApplicationWindow
content area was changed. I used a custom item derived from QQuickFramebufferObject
to fix it. You can find example on GitHub.
In my example, when the FBO__
macros is not defined the code from QtQuick Scenegraph OpenGL-under-Qml example is used. And the setClearBeforeRendering(false)
is not working anymore. I believe ApplicationWindow
erases the whole window background when GUI rendering occurs. I had an idea to intercept somehow (by flags
property and event handlers) the erase background event, but still has not performed it. A custom item based on QQuickFramebufferObject
works fine, but I think it has a memory overhead compared to painting in QQuickQindow::beforeRendering()
.