| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #include "widget.h"
- #include <QApplication>
- #include <QCoreApplication>
- #include <QOpenGLContext>
- #include <QSurfaceFormat>
- #include "loginit.h"
- #include <QLibrary>
- #include <QDebug>
- void test();
- int main(int argc, char *argv[])
- {
- // 可选:强制走桌面 OpenGL(避免走 OpenGLES)
- // QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
- QSurfaceFormat fmt;
- fmt.setRenderableType(QSurfaceFormat::OpenGL);
- fmt.setVersion(3, 3);
- fmt.setProfile(QSurfaceFormat::CoreProfile); // 或 CompatibilityProfile
- 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();
- qDebug() << "Requested Qt SurfaceFormat: renderable=" << fmt.renderableType()
- << "version=" << fmt.majorVersion() << "." << fmt.minorVersion()
- << "profile=" << fmt.profile();
- }
-
- widget w;
- w.show();
- // 打印“实际创建到的版本”(创建 widget 后上下文通常已可用;更精确的实际值也会在 PlayerGLWidget::initializeGL() 中打印)
- if (QOpenGLContext::currentContext()) {
- const QSurfaceFormat fmt = QOpenGLContext::currentContext()->format();
- qDebug() << "Current Qt OpenGLContext: isOpenGLES=" << QOpenGLContext::currentContext()->isOpenGLES()
- << "version=" << fmt.majorVersion() << "." << fmt.minorVersion()
- << "profile=" << fmt.profile();
- } else {
- qDebug() << "Current Qt OpenGLContext: (null at main)";
- }
- return a.exec();
- }
|