Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-120949

Drawing a triangle doesn't work on laptop Asus K53SV with Mesa using Qt 6.7.0 beta1

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P1: Critical
    • None
    • 6.7.0 Beta1
    • GUI: OpenGL
    • None
    • Asus K53SV, Intel HD Graphics 3000; Nvidia GeForce GT 540M (1 GB)
    • Windows

    Description

      The example below should draw a red triangle but it draws nothing. It prints: OpenGL version, GLSL version, and vendor:

      ```
      OpenGL Version: 3.0 Mesa 11.2.2
      GLSL Version: 1.30
      OpenGL Vendor: VMware, Inc.
      ```

      main.cpp

      ```

      #include <QtGui/QOpenGLFunctions>
      #include <QtGui/QSurfaceFormat>
      #include <QtOpenGLWidgets/QOpenGLWidget>
      #include <QtOpenGL/QOpenGLBuffer>
      #include <QtOpenGL/QOpenGLShaderProgram>
      #include <QtWidgets/QApplication>

      class OpenGLWidget : public QOpenGLWidget, private QOpenGLFunctions
      {
      public:
          OpenGLWidget()
         

      {         resize(350, 350);         setWindowTitle("OpenGL Triangle");     }

      private:
          void initializeGL() override
          {
              initializeOpenGLFunctions();
              glClearColor(0.4f, 0.8f, 0.9f, 1.f);

              qDebug() << "OpenGL Version:" << (const char*) glGetString(GL_VERSION);
              qDebug() << "GLSL Version:" << (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION);
              qDebug() << "OpenGL Vendor:" << (const char*) glGetString(GL_VENDOR);

              QString vertexShaderSource =
                  "attribute vec2 aPosition;\n"
                  "void main()\n"
                  "

      {\n"             "    gl_Position = vec4(aPosition, 0.0, 1.0);\n"             "}

      \n";

              QString fragmentShaderSource =
                  "#ifdef GL_ES\n"
                  "precision mediump float;\n"
                  "#endif\n"
                  "//out vec4 fragColor;\n"
                  "void main()\n"
                  "

      {\n"             "    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"             "}

      \n";

              m_program.create();
              m_program.addShaderFromSourceCode(QOpenGLShader::ShaderTypeBit::Vertex,
                                                vertexShaderSource);
              m_program.addShaderFromSourceCode(QOpenGLShader::ShaderTypeBit::Fragment,
                                                fragmentShaderSource);
              m_program.link();
              m_program.bind();

              float vertPositions[] =

      {             -0.5f, -0.5f,             0.5f, -0.5f,             0.f, 0.5f         }

      ;
              m_vertPosBuffer.create();
              m_vertPosBuffer.bind();
              m_vertPosBuffer.allocate(vertPositions, sizeof(vertPositions));
              m_program.setAttributeBuffer("aPosition", GL_FLOAT, 0, 2);
              m_program.enableAttributeArray("aPosition");
          }

          void paintGL() override
         

      {         glClear(GL_COLOR_BUFFER_BIT);         glDrawArrays(GL_TRIANGLES, 0, 4);     }

      private:
          QOpenGLShaderProgram m_program;
          QOpenGLBuffer m_vertPosBuffer;
      };

      int main(int argc, char *argv[])

      {     QApplication app(argc, argv);     OpenGLWidget w;     w.show();     return app.exec(); }

      ```

      pro

      ```

      QT += core gui openglwidgets widgets

      win32: LIBS += -lopengl32

      CONFIG = c+17

      SOURCES += \
          main.cpp
      ```

      I can active the integrated video card instead of Mesa by adding the `AA_UseDesktopOpenGL` attribute:

      ```

      int main(int argc, char *argv[])
      {
          QApplication::setAttribute(Qt::ApplicationAttribute::AA_UseDesktopOpenGL);

      ```

      The example above prints an info about the integrated card now:

      ```

      OpenGL Version: 3.1.0 - Build 9.17.10.4459
      GLSL Version: 1.40 - Intel Build 9.17.10.4459
      OpenGL Vendor: Intel
      ```

      But a triangle is white instead of red:

      To active the discrete video card I should add these lines of code to main.cpp for GeForce and Radeon:

      ```
      #ifdef _WIN32
      #include <windows.h>
      extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
      extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001;
      #endif
      ```

      It prints this info:

      ```
      OpenGL Version: 4.6.0 NVIDIA 391.35
      GLSL Version: 4.60 NVIDIAOpenGL
      Vendor: NVIDIA Corporation
      ```
      But a triangle is still white.

      Topic: https://forum.qt.io/topic/153686/drawing-a-triangle-doesn-t-work-on-laptop-asus-k53sv-with-mesa-using-qt-6-7-0-beta1

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            lagocs Laszlo Agocs
            8observer8 Ivan Enzhaev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes