QGLWidget appears black in Windows 7

吃可爱长大的小学妹 提交于 2019-12-05 14:27:16

If your program works in Windows XP but not in Windows 7, I recommend that you should check if there is a newer version of the display driver.

You're using OpenGL API outside of paintGL(), resizeGL(), or initializeGL().

When your slot is called, modify any state to be able to draw the new frame, but don't call OpenGL API yet. Instead, call QWidget::updateGL(), and do the OpenGL calls in your reimplementation of paintGL().

The problem you're experiencing is that, outside these three functions, your GL context isn't the current one. On older OSs, that might not be a problem, but any OS with a compositing window manager will make problems. E.g., in your case, your program may have been the only OpenGL user under XP, so yours was always the current context. But in Windows 7, the desktop itself uses, if not OpenGL, then Direct3D, ie. the same hardware.

If you absolutely must call OpenGL function outside those three functions, you need to call QGLWidget::makeCurrent() first, but note that this is not idiomatic use.

Regarding the QTimer creation in initializeGL(): it's certainly more idiomatic to create that timer in the class' constructor, but it should be ok in initializeGL(), too.

Hi I had a similar problem (black screen with intermittently correctly drawn image) with new NVIDIA drivers (280.something) + Win7, I fixed the problem by removing the manual swapBuffers call at the end of my paintGL and in the constructor setting setAutoBufferSwap(true) - hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!