[solved] How to create OpenGL 3.3 Context with QQuickView?



  • How can I create and use my own OpenGL 3.3 Context with QQuickView?

    I will paint a scene and using modern OpenGL functions. (like context 3.3 or 4.4)
    I will paint either on the QQuickView window background or in a QQuickItem.



  • Via setFormat().

    QSurfaceFormat format;
    format.setVersion(3, 3);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setDepthBufferSize(24);
    format.setStencilBufferSize(8);
    QQuickView view;
    view.setFormat(format);
    ...



  • I have changed the Qt example "openglunderqml"

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

    qmlRegisterType<Squircle>("OpenGLUnderQML", 1, 0, "Squircle");
    
    QSurfaceFormat format;
    format.setVersion(3, 3);
    format.setProfile&#40;QSurfaceFormat::CoreProfile&#41;;
    format.setDepthBufferSize(24);
    format.setStencilBufferSize(8);
    QQuickView view;
    view.setFormat(format);
    view.setResizeMode(QQuickView::SizeRootObjectToView);
    view.setSource(QUrl("qrc:///scenegraph/openglunderqml/main.qml"));
    view.show();
    
    return app.exec();
    

    }@

    The first error after start this is:

    @QOpenGLShader::compile(Vertex): Vertex shader failed to compile with the following errors:
    ERROR: error(#272) Implicit version number 110 not supported by GL3 forward compatible context@

    I changed now in squircle.cppthe two addShaderFromSourceCode functions by adding "#version 330\n":
    @
    void SquircleRenderer::paint()
    {
    ...
    m_program->addShaderFromSourceCode(... ,
    "#version 330\n"
    "attribute highp vec4 vertices;"
    ...
    ...
    ...
    );
    m_program->addShaderFromSourceCode(... ,
    "#version 330\n"
    "uniform lowp float t;"
    ...
    ...
    ...
    );
    ...
    }
    @

    The result is a black background (not the pulsing colored) with the normal QML text element over it.

    Have I forgot something? (eg. #include<...>)
    When yes, what?



  • That's not a valid version 330 shader. There is no attribute keyword there. Try:

    #version 330
    in vec4 vertices;
    ...

    Also, watch out for the fact that you are now using core profile so thinsg like mandatory usage of vertex array objects, no client-side pointers, etc. will all apply.



  • Thanks, so only change the shader code is not enough for the example.

    I'm porting a Qt 5.1 Project to Qt 5.3.1 and whould use a CompatibilityProfile.

    In the "openglunderqml" example, using a CompatibilityProfile instead of CoreProfile result in crash the ATI driver in function
    @atio6axx!DrvPresentBuffers
    @

    Is it allowed to use a CompatibilityProfile with setFormat()?



  • I think I have found the answer.

    @format.setOption(QSurfaceFormat::DeprecatedFunctions);
    @

    You have posted the solution at:
    http://qt-project.org/forums/viewthread/42842/#177608

    A tip in the documentation of QOpenGLContext would be helpfull.
    Like AMD drivers make this necessary.

    I have wasted one week of work for one line of code :)



  • That is AMD specific and we can't possibly document all vendor or driver-version specific idiosyncrasies in the Qt docuemntation. I'm pretty sure it works fine on nVidia without the DeprecatedFunctions option (or maybe I'm thinking of Core profile).


Log in to reply
 

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