1

I want to use Qt Quick 2.x for my program but I can't make it work with OpenGL > 2.0

I have main.qml:

/* imports */
Window {
    ...
    Scene {
        ...
    }
    ...
}

In Scene I'm using OpenGL > 2.0 so my shaders aren't working.

I've tried to add this line qobject_cast<QQuickWindow*>(engine.rootObjects().first())->setFormat(format_3_3); in main.cpp but that didn't help.

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QSurfaceFormat format_3_3;
    format_3_3.setMajorVersion(3);
    format_3_3.setMinorVersion(3);
    format_3_3.setProfile(QSurfaceFormat::CompatibilityProfile);

    qmlRegisterType<Scene>("SceneGL", 1, 0, "Scene");

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    qobject_cast<QQuickWindow*>(engine.rootObjects().first())->setFormat(format_3_3);

    return app.exec();
}

My Scene class:

class Scene : public QQuickItem
{
    ...
}

I found a solution here (47 minute) but without source code I can't see full picture to use the same technique.

How can I solve this problem?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Eugene Kolesnikov
  • 643
  • 2
  • 6
  • 15
  • 1
    windows? then you need to configure your QT install to use openGL otherwise it just has opengl ES 2.0 see: http://stackoverflow.com/questions/26813229/qt-and-native-opengl-support-in-ms-windows – ratchet freak Nov 09 '14 at 10:51
  • I'm using Mac OS X 10.10 – Eugene Kolesnikov Nov 09 '14 at 10:53
  • Mac does not implement Compatibility profiles. You need to request a Core profile if you want GL >= 3.x. Moreover, the way you set the format is totally hackish. Much better to subclass QQuickWindow and set the format in the constructor of your subclass. – peppe Nov 09 '14 at 22:48

0 Answers0