main.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "widget.h"
  2. #include <QApplication>
  3. #include <QCoreApplication>
  4. #include <QOpenGLContext>
  5. #include <QSurfaceFormat>
  6. #include "loginit.h"
  7. #include <QLibrary>
  8. #include <QDebug>
  9. #include "LHQLogAPI.h"
  10. void test();
  11. int main(int argc, char *argv[])
  12. {
  13. // Windows 下优先强制走桌面 OpenGL(避免 Qt 走 ANGLE/OpenGLES 导致拿不到 3.3 Core 函数表)
  14. // 注意:必须在 QApplication 构造之前设置。
  15. #if defined(Q_OS_WIN)
  16. QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
  17. #endif
  18. QSurfaceFormat fmt;
  19. fmt.setRenderableType(QSurfaceFormat::OpenGL);
  20. fmt.setVersion(3, 3);
  21. // Windows 驱动对 CoreProfile 的支持差异更大;兼容性 Profile 更容易创建成功。
  22. fmt.setProfile(QSurfaceFormat::CoreProfile);
  23. fmt.setDepthBufferSize(24);
  24. fmt.setStencilBufferSize(8);
  25. // fmt.setSamples(4); // 需要抗锯齿就打开
  26. QSurfaceFormat::setDefaultFormat(fmt);
  27. QApplication a(argc, argv);
  28. /* 初始化log */
  29. init_log();
  30. // 打印“请求的版本”(defaultFormat)
  31. {
  32. const QSurfaceFormat fmt = QSurfaceFormat::defaultFormat();
  33. LH_WRITE_LOG(QString("Requested Qt SurfaceFormat: renderable=%1 version=%2.%3 profile=%4")
  34. .arg(fmt.renderableType() == QSurfaceFormat::OpenGL ? "OpenGL" :
  35. fmt.renderableType() == QSurfaceFormat::OpenGLES ? "OpenGLES" : "Default")
  36. .arg(fmt.majorVersion())
  37. .arg(fmt.minorVersion())
  38. .arg(fmt.profile() == QSurfaceFormat::CoreProfile ? "Core" :
  39. fmt.profile() == QSurfaceFormat::CompatibilityProfile ? "Compatibility" : "NoProfile"));
  40. }
  41. widget w;
  42. w.show();
  43. // 说明:在 main() 里通常不会有 current OpenGL context(要等 QOpenGLWidget::initializeGL/painGL)。
  44. // 实际创建到的上下文与版本会在 PlayerGLWidget::initializeGL() 的日志中打印。
  45. LH_WRITE_LOG("Current Qt OpenGLContext: (expected null at main; created when QOpenGLWidget initializes)");
  46. return a.exec();
  47. }