QOpenGLWidget show black screen

前端 未结 3 1870
北荒
北荒 2021-01-28 20:38

I tried the QOpenGLWidget example described here: https://stackoverflow.com/a/31524956/4564882

but I get only a black widget. The code is exactly the same. this the code

相关标签:
3条回答
  • 2021-01-28 21:08

    The problem was because I use Qt5 binaries built with the default configuration. The default in Qt 5.5 is "dynamic" GL -- both ANGLE (ES2)

    ANGLE ((Almost Native Graphics Layer Engine) is an open source project by Google. Its aim is to map OpenGL ES 2.0 API calls to DirectX 9 API.)

    and Desktop backends (Desktop OpenGL)are built, the decision on which one to use is taken at runtime.

    The problem is that ANGLE only supports OpenGL>3.x, so the first code that I test is deprecated and not supported by ANGLE. The second is supported, that's why it worked.

    So, I rebuild Qt to target Desktop OpenGL only to support my deprecated code, using:

    configure -debug-and-release -opensource -opengl desktop -platform win32-msvc2015
    

    and then run nmake, link my application to the new binaries, and my code works well!

    0 讨论(0)
  • 2021-01-28 21:10

    In my case, my laptop uses NVIDIA external graphics card. So I went to NVIDIA Control Panel -> Manage 3D Settings -> Program Settings, and then selected "high-performance" for the .EXE file. This worked.

    0 讨论(0)
  • 2021-01-28 21:13

    I had a black screen on desktop. I solved the problem by adding this line of code:

    QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
    

    For example, put it here:

    #include "widget.h"
    
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
        QApplication a(argc, argv);
        Widget w;
        w.show();
        return a.exec();
    }
    
    0 讨论(0)
提交回复
热议问题