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] QOpenGLWidget and CoreProfile : nothing displayed when using setVersion option
Forum Updated to NodeBB v4.3 + New Features

[Solved] QOpenGLWidget and CoreProfile : nothing displayed when using setVersion option

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.9k Views 2 Watching
  • 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.
  • S Offline
    S Offline
    Soax
    wrote on last edited by Soax
    #1

    Hi,

    I've met a very strange error while using OpenGl with Qt 5.4.

    I use the new QOpenGLWidget class, and OpenGL Core Profile.

    If I choose a version for OpenGL, (3.1, 3.3, 4.3, etc...) then nothing is displayed !
    I just have the screen filled with the clear color

        format.setVersion(4, 4);
        format.setProfile(QSurfaceFormat::CoreProfile);
        format.setDepthBufferSize(24);
        format.setStencilBufferSize(8);
        QSurfaceFormat::setDefaultFormat(format);
    

    If I don't choose any version, graphics are displayed.

        format.setProfile(QSurfaceFormat::CoreProfile);
        format.setDepthBufferSize(24);
        format.setStencilBufferSize(8);
        QSurfaceFormat::setDefaultFormat(format);
    

    What's wrong with this option ?
    The problem is that I want to port my code from Linux to Max and that I have to use this setVersion option on Mac...

    Thanks,
    Soax

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      It's hard to say without seeing the whole code. You're probably using some functionality that is deprecated and not present in the newer core profiles. Another possibility is that you don't meet some requirements for correct rendering setup in core profile.

      One such requirement is that in core profiles (starting with 3.something, I don't remember which) you must use a VAO. If you don't have any VAO specific code it's enough to create one, bind it and never touch again until the end of program where you release it.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Soax
        wrote on last edited by
        #3

        Hi thank you for your answer,

        First I did'nt use VAO, then I added the

        format.setProfile(QSurfaceFormat::CoreProfile);
        

        and nothing was displayed. Then I added VAO and display was back.

        Then I added this single line

        format.setVersion(4, 4);
        

        and again nothing is displayed. I tried with several version (3.1, 3.3, 4.1, 4.4), but without change.

        Here is my initialisation code :

        build_program();
        
        model = glm::mat4(1.0f);
        view = glm::mat4(1.0f);
        projection = glm::ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
        mvp = projection * view * model;
        
        glGenBuffers(1, &vbo_id);
        glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
        glBufferData(GL_ARRAY_BUFFER, sizeof(vertices_c) + sizeof(texture_c), NULL, GL_STATIC_DRAW);
        glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices_c), vertices_c);
        glBufferSubData(GL_ARRAY_BUFFER, sizeof(vertices_c), sizeof(texture_c), texture_c);
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        
        #ifndef QT_WINDOW_H
        glGenVertexArrays(1, &vao_id);
        glBindVertexArray(vao_id);
        #else
        m_vao.create();
        QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
        #endif
        glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
        
        glVertexAttribPointer(attribute_vc, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
        glEnableVertexAttribArray(attribute_vc);
        glVertexAttribPointer(attribute_tc, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(vertices_c)));
        glEnableVertexAttribArray(attribute_tc);
        
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        #ifndef QT_WINDOW_H
        glBindVertexArray(0);
        #endif
        

        And here is my paint code :

        update();
        
        glViewport(pos_x, *(this->win_height) - pos_y - height, width, height);
        
        glUseProgram(program);
        #ifndef QT_WINDOW_H
        glBindVertexArray(vao_id);
        #else
        QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
        #endif
        glUniformMatrix4fv(uniform_mvp, 1, GL_FALSE, &mvp[0][0]);
        glUniform1i(uniform_number_of_textures, number_of_textures);
        glBindTexture(GL_TEXTURE_2D_ARRAY, texture_id);
        glUniform1i(uniform_texture, 0);
        
        glDrawArrays(GL_QUADS, 0, 4);
        
        glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
        #ifndef QT_WINDOW_H
        glBindVertexArray(0);
        #endif
        glUseProgram(0);
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          Soax
          wrote on last edited by
          #4

          What I do not understand is why it doesn't work when I set the version but works when the version is not set.
          In both cases I set the profile to CoreProfile.

          When the version is not set, it's version 4.4 that is used (according to GL_VERSION), and it works fine.
          But when I set the version to 4.4 (the same), it doesn't work...

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #5

            If I recall correctly an OpenGL implementation is free to give you a "close enough" superset of what you requested if the specific context is not available.

            If you don't specify a version I believe it tries to create a 2.1 context. Since 2.x version don't have a core profile the implementation is free to give you any kind of superset and you are getting a 4.4 compatible profile (not the core one).

            When you set the version explicitly to 4.4 it has a core profile so that's what is selected.

            So I suspect your code still doesn't run in core profile, it's just that you're getting a compatible profile by mistake.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Soax
              wrote on last edited by
              #6

              Thanks a lot !

              I checked with

              context()->format().profile();
              

              once the context is created and the code is not running in core profile if there is not a particular version specified...

              This should be mentionned in Qt QSurfaceFormat documentation.

              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