An interesting question about opengl using QOpenGLWidget
-
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. -
Hi,
When exactly does it happen ? When your application is moved back to your main screen ? After your re-build ?
-
@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. -
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 ?
-
@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.☹ -
Could be related to your graphics card driver.
-
@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.