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. An interesting question about opengl using QOpenGLWidget
Forum Updated to NodeBB v4.3 + New Features

An interesting question about opengl using QOpenGLWidget

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 1.1k Views 1 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.
  • Qt_crazyerQ Offline
    Qt_crazyerQ Offline
    Qt_crazyer
    wrote on last edited by Qt_crazyer
    #1

    I am learning opengl recently, and I have do some code on qt. Using QOpenGLWidget, I can draw my own 3D garphics. I did it. I configured a new monitor for my laptop as an extension screen. So I can code and debug more conveniently. It still worked correctly. But while I close the extension screen(only my laptop screen), my 3d graphics cannot be displayed. It's all black.):
    I don't know how to solve this puzzling problem, although I've done a lot of trying. Here is my shader:

    const char *vertexShaderSource = "#version 330 core\n"
        "layout (location = 0) in vec3 aPos;\n"
        "layout (location = 1) in vec3 color;\n"
        "layout (location = 2) in vec3 colorLine;\n"
        "out vec4 col;\n"
        "uniform mat4 model;\n"
        "uniform mat4 view;\n"
        "uniform mat4 projection;\n"
        "uniform bool useLineColor;\n"
        "void main()\n"
        "{\n"
        " gl_Position = projection * view * model * vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
        " if(useLineColor) col = vec4(colorLine.x/255.0f, colorLine.y/255.0f, colorLine.z/255.0f, 1.0);\n"
        " else col = vec4(color.x/255.0f, color.y/255.0f, color.z/255.0f, 1.0);\n"
        "}\0";
    const char *fragmentShaderSource = "#version 330 core\n"
        "out vec4 FragColor;\n"
        "in vec4 col;\n"
        "void main()\n"
        "{\n"
        " FragColor = col;\n"
        "}\n\0";
    

    My laptop screen resolution is 19201080, and my new extension screen resolution is 1440900.
    How should I solve this problem or debug my code to find the ultimate cause?
    Thanks for any advice.
    Qt Creator 5.9.1 on Windows10
    MSVC2015 64bit complier.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      When exactly does it happen ? When your application is moved back to your main screen ? After your re-build ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Qt_crazyerQ 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        When exactly does it happen ? When your application is moved back to your main screen ? After your re-build ?

        Qt_crazyerQ Offline
        Qt_crazyerQ Offline
        Qt_crazyer
        wrote on last edited by
        #3

        @SGaist
        The first time this problem occurred was when I closed the extension screen. So the application has to move back to my main screen. And it still worked well. Then I closed the application. I want to debug my code on my main screen. I re-run my application, but it changed to be all black.
        But what's interesting is that as long as I open my extension screen, no matter which screen the application is displayed, it can display my 3D graphics normally. Once I close the extension screen, it fails. And I have tried to re-build my application. Nothing seemed to work.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Can you check whether a more recent version of Qt also behaves like that ?

          By the way, what graphic card do you have on your sytem ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          Qt_crazyerQ 1 Reply Last reply
          0
          • SGaistS SGaist

            Can you check whether a more recent version of Qt also behaves like that ?

            By the way, what graphic card do you have on your sytem ?

            Qt_crazyerQ Offline
            Qt_crazyerQ Offline
            Qt_crazyer
            wrote on last edited by
            #5

            @SGaist
            while, I just have Qt Creator 5.9.1. And my graphic card is NVIDIA GeForce GTX 1050 and Intel(R) HD graphics 630. Maybe I should find another version of qt to have a try. I still examine every line of code carefully. There's no finding out where the problem is.☹

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Could be related to your graphics card driver.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              Qt_crazyerQ 1 Reply Last reply
              1
              • SGaistS SGaist

                Could be related to your graphics card driver.

                Qt_crazyerQ Offline
                Qt_crazyerQ Offline
                Qt_crazyer
                wrote on last edited by
                #7

                @SGaist
                Yeah, you are right. It's really related to the graphics card.
                After I determined that my code was no problem, I began to look for all other possible problems. I updated my graphics driver. Check out the OpenGL version that my graphics card supports. There is no problem. In the end, I wonder if my computer is switching the graphics card automatically, and every time I open the expansion screen, my computer will run my gtx1050. After closing the expansion screen, my computer will give priority to running my integrated graphics card. So I tried to force my application to run on my independent graphics card. It runs perfectly.
                I don't know if my explanation is correct, but it does solve my problem.
                Thank you for your reply.

                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