Solved :
I found a simpler way to achieve my purpose. I force the application to use opengl render and register a class as QDeclarativeItem in which I put my openGL.
main.cpp:
int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
// 3D Scene Binding
qmlRegisterType<RenderItem>("RenderItem", 1, 0, "Scene3D");
// classic Qt init
QmlApplicationViewer viewer;
// update timer
QObject::connect(&repaintTimer,
SIGNAL(timeout
()),
&viewer,
SLOT(update
()));
repaintTimer.setSingleShot(false);
repaintTimer.start(0);
// --
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
viewer.
setRenderHints(QPainter::HighQualityAntialiasing);
viewer.setResizeMode(QDeclarativeView::SizeRootObjectToView);
viewer.showExpanded();
return app->exec();
}
int main(int argc, char *argv[])
{
QApplication::setGraphicsSystem("opengl");
QScopedPointer<QApplication> app(createApplication(argc, argv));
// 3D Scene Binding
qmlRegisterType<RenderItem>("RenderItem", 1, 0, "Scene3D");
// classic Qt init
QmlApplicationViewer viewer;
// update timer
QTimer repaintTimer;
QObject::connect(&repaintTimer, SIGNAL(timeout()), &viewer, SLOT(update()));
repaintTimer.setSingleShot(false);
repaintTimer.start(0);
// --
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
viewer.setRenderHints(QPainter::HighQualityAntialiasing);
viewer.setResizeMode(QDeclarativeView::SizeRootObjectToView);
viewer.setMainQmlFile(QLatin1String("qml/main.qml"));
viewer.showExpanded();
return app->exec();
}
To copy to clipboard, switch view to plain text mode
RenderItem.h:
class RenderItem : public QDeclarativeItem
{
Q_OBJECT
public:
RenderItem(QDeclarativeItem* parent = 0)
{
// Tell to Qt Declarative that this item have to be draw
}
~RenderItem();
{
painter->beginNativePainting();
if (!m_bGLInitialized)
// No relation of QGLWidget method (I just didn't change names)
initializeGL();
if (mWidth != width() || mHeight != height())
{
mWidth = width(); mHeight = height();
// No relation of QGLWidget method (I just didn't change names)
resizeGL(mWidth, mHeight);
}
// No relation of QGLWidget method (I just didn't change names)
paintGL();
painter->endNativePainting();
}
...
}
class RenderItem : public QDeclarativeItem
{
Q_OBJECT
public:
RenderItem(QDeclarativeItem* parent = 0)
{
// Tell to Qt Declarative that this item have to be draw
setFlag(QGraphicsItem::ItemHasNoContents, false);
}
~RenderItem();
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->beginNativePainting();
if (!m_bGLInitialized)
// No relation of QGLWidget method (I just didn't change names)
initializeGL();
if (mWidth != width() || mHeight != height())
{
mWidth = width(); mHeight = height();
// No relation of QGLWidget method (I just didn't change names)
resizeGL(mWidth, mHeight);
}
// No relation of QGLWidget method (I just didn't change names)
paintGL();
painter->endNativePainting();
}
...
}
To copy to clipboard, switch view to plain text mode
main.qml:
import QtQuick 1.1
import RenderItem 1.0
Rectangle {
id: main
width: 1024
height: 600
Scene3D {
anchors.centerIn: parent
anchors.fill: parent
}
...
}
import QtQuick 1.1
import RenderItem 1.0
Rectangle {
id: main
width: 1024
height: 600
Scene3D {
anchors.centerIn: parent
anchors.fill: parent
}
...
}
To copy to clipboard, switch view to plain text mode
Notes: If you are using FBO just take care of backup and restore the current FBO ID each frames, else you will have conflicts between your scene and qml GUI (in some cases your window can just stay white).
Bookmarks