main.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. void test();
  10. int main(int argc, char *argv[])
  11. {
  12. // 可选:强制走桌面 OpenGL(避免走 OpenGLES)
  13. // QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
  14. QSurfaceFormat fmt;
  15. fmt.setRenderableType(QSurfaceFormat::OpenGL);
  16. fmt.setVersion(3, 3);
  17. fmt.setProfile(QSurfaceFormat::CoreProfile); // 或 CompatibilityProfile
  18. fmt.setDepthBufferSize(24);
  19. fmt.setStencilBufferSize(8);
  20. // fmt.setSamples(4); // 需要抗锯齿就打开
  21. QSurfaceFormat::setDefaultFormat(fmt);
  22. QApplication a(argc, argv);
  23. /* 初始化log */
  24. init_log();
  25. // 打印“请求的版本”(defaultFormat)
  26. {
  27. const QSurfaceFormat fmt = QSurfaceFormat::defaultFormat();
  28. qDebug() << "Requested Qt SurfaceFormat: renderable=" << fmt.renderableType()
  29. << "version=" << fmt.majorVersion() << "." << fmt.minorVersion()
  30. << "profile=" << fmt.profile();
  31. }
  32. widget w;
  33. w.show();
  34. // 打印“实际创建到的版本”(创建 widget 后上下文通常已可用;更精确的实际值也会在 PlayerGLWidget::initializeGL() 中打印)
  35. if (QOpenGLContext::currentContext()) {
  36. const QSurfaceFormat fmt = QOpenGLContext::currentContext()->format();
  37. qDebug() << "Current Qt OpenGLContext: isOpenGLES=" << QOpenGLContext::currentContext()->isOpenGLES()
  38. << "version=" << fmt.majorVersion() << "." << fmt.minorVersion()
  39. << "profile=" << fmt.profile();
  40. } else {
  41. qDebug() << "Current Qt OpenGLContext: (null at main)";
  42. }
  43. return a.exec();
  44. }