Mixing modern OpenGL and QML



  • Hi,

    We are using developing an application in Qt 5.3.2. We would like to make a custom drawn QML element using QQuickFrameBufferObject and OpenGL 3.3 core profile functions which is higher than the one used standard by QML.

    We would like to know what the best approach to drawing only our element with modern OpenGL and not touch the QML context?

    What we do right now is :

    • Create a QOpenGLContext and QOffscreenSurface set to use Qt 5.3.2
    • We set the share context of our own QOpenGLContext with the context used by QML
    • Before we start rendering we make our own OpenGL context current and after rendering has finished we make the QML context current.

    Is this correct or do we need to make changes? Do we need to call QQuickWindow::resetOpenGLState()

    Thanks!



  • Take a look at the "textureingsnode" example. It shows how to use the QQuickFrameBufferObject. I'm using that and it seems to work.

    I don't create a separate context for my custom OpenGL code.

    I do all my rendering from a class derived from QOpenGLFunctions_4_5_Core.

    At the beginning, before create your Q*Application i call:

    void initliaseOpenGL()
    {

    QApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
    QSurfaceFormat format;
    format.setDepthBufferSize(24);
    format.setStencilBufferSize(8);
    format.setSamples(4);
    format.setVersion(4, 5);
    format.setRenderableType(QSurfaceFormat::OpenGL);
    format.setProfile(QSurfaceFormat::CoreProfile);
    #ifdef QT_DEBUG
    format.setOption(QSurfaceFormat::DebugContext);
    #endif
    QSurfaceFormat::setDefaultFormat(format);
    }

    to set up OpenGL.

    Now if i change the format.setVersion(4, 5); to format.setVersion(3, 1); I get a crash during openGL init, indicating that it is using a 4.5 core profile, and that the code pasted above is having an effect.



  • @tomkulaga

    Hi,

    We cannot do this because if we are making a QML application in Qt 5.3.2. If we set the format to anything above OpenGL 2.0 nothing gets rendered.

    Maybe I should also mention we are developing for Ubuntu 14.04, since we have seen difference on how the initializeOpenGlFunctions works on Linux and on Windows.



  • You might want to consider using Qt Canvas 3D.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.