Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] How to create OpenGL 3.3 Context with QQuickView?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 3.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bugtracker
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      agocs
      wrote on last edited by
      #2

      Via setFormat().

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

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bugtracker
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          agocs
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Bugtracker
            wrote on last edited by
            #5

            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()?

            1 Reply Last reply
            0
            • B Offline
              B Offline
              Bugtracker
              wrote on last edited by
              #6

              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 :)

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                ZapB
                wrote on last edited by
                #7

                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).

                Nokia Certified Qt Specialist
                Interested in hearing about Qt related work

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved