#include "widget.h" #include #include #include #include #include "loginit.h" #include #include #include "LHQLogAPI.h" void test(); int main(int argc, char *argv[]) { // Windows 下优先强制走桌面 OpenGL(避免 Qt 走 ANGLE/OpenGLES 导致拿不到 3.3 Core 函数表) // 注意:必须在 QApplication 构造之前设置。 #if defined(Q_OS_WIN) QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL); #endif QSurfaceFormat fmt; fmt.setRenderableType(QSurfaceFormat::OpenGL); fmt.setVersion(3, 3); // Windows 驱动对 CoreProfile 的支持差异更大;兼容性 Profile 更容易创建成功。 fmt.setProfile(QSurfaceFormat::CoreProfile); fmt.setDepthBufferSize(24); fmt.setStencilBufferSize(8); // fmt.setSamples(4); // 需要抗锯齿就打开 QSurfaceFormat::setDefaultFormat(fmt); QApplication a(argc, argv); /* 初始化log */ init_log(); // 打印“请求的版本”(defaultFormat) { const QSurfaceFormat fmt = QSurfaceFormat::defaultFormat(); LH_WRITE_LOG(QString("Requested Qt SurfaceFormat: renderable=%1 version=%2.%3 profile=%4") .arg(fmt.renderableType() == QSurfaceFormat::OpenGL ? "OpenGL" : fmt.renderableType() == QSurfaceFormat::OpenGLES ? "OpenGLES" : "Default") .arg(fmt.majorVersion()) .arg(fmt.minorVersion()) .arg(fmt.profile() == QSurfaceFormat::CoreProfile ? "Core" : fmt.profile() == QSurfaceFormat::CompatibilityProfile ? "Compatibility" : "NoProfile")); } widget w; w.show(); // 说明:在 main() 里通常不会有 current OpenGL context(要等 QOpenGLWidget::initializeGL/painGL)。 // 实际创建到的上下文与版本会在 PlayerGLWidget::initializeGL() 的日志中打印。 LH_WRITE_LOG("Current Qt OpenGLContext: (expected null at main; created when QOpenGLWidget initializes)"); return a.exec(); }