summaryrefslogtreecommitdiffstats
path: root/examples/opengl/hellogl2
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-09-26 16:08:55 +0200
committerLiang Qi <liang.qi@qt.io>2017-09-26 16:14:54 +0200
commitaadfe7d634de04519102c5827ca885dc2e2199c9 (patch)
treed92db346ca95332b177036a53f1f6beb2e24fb74 /examples/opengl/hellogl2
parent4b6c1448047362b8c38d265e6414f0e3e59b8d37 (diff)
parenta732e16d5fd9dbf8a0289fec9f948b12e9ba2c19 (diff)
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts: src/gui/kernel/qguiapplication.cpp src/platformsupport/input/libinput/qlibinputpointer.cpp src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h src/plugins/platforms/cocoa/qcocoawindow.h src/testlib/qtestsystem.h Change-Id: I5975ffb3261c2dd82fe02ec4e57df7c0950226c5
Diffstat (limited to 'examples/opengl/hellogl2')
-rw-r--r--examples/opengl/hellogl2/glwidget.cpp7
-rw-r--r--examples/opengl/hellogl2/glwidget.h5
-rw-r--r--examples/opengl/hellogl2/main.cpp27
3 files changed, 33 insertions, 6 deletions
diff --git a/examples/opengl/hellogl2/glwidget.cpp b/examples/opengl/hellogl2/glwidget.cpp
index fc961da4c4..318adb5043 100644
--- a/examples/opengl/hellogl2/glwidget.cpp
+++ b/examples/opengl/hellogl2/glwidget.cpp
@@ -54,6 +54,8 @@
#include <QCoreApplication>
#include <math.h>
+bool GLWidget::m_transparent = false;
+
GLWidget::GLWidget(QWidget *parent)
: QOpenGLWidget(parent),
m_xRot(0),
@@ -61,10 +63,9 @@ GLWidget::GLWidget(QWidget *parent)
m_zRot(0),
m_program(0)
{
- m_core = QCoreApplication::arguments().contains(QStringLiteral("--coreprofile"));
+ m_core = QSurfaceFormat::defaultFormat().profile() == QSurfaceFormat::CoreProfile;
// --transparent causes the clear color to be transparent. Therefore, on systems that
// support it, the widget will become transparent apart from the logo.
- m_transparent = QCoreApplication::arguments().contains(QStringLiteral("--transparent"));
if (m_transparent) {
QSurfaceFormat fmt = format();
fmt.setAlphaBufferSize(8);
@@ -127,6 +128,8 @@ void GLWidget::setZRotation(int angle)
void GLWidget::cleanup()
{
+ if (m_program == nullptr)
+ return;
makeCurrent();
m_logoVbo.destroy();
delete m_program;
diff --git a/examples/opengl/hellogl2/glwidget.h b/examples/opengl/hellogl2/glwidget.h
index cff5633893..21dd200dc7 100644
--- a/examples/opengl/hellogl2/glwidget.h
+++ b/examples/opengl/hellogl2/glwidget.h
@@ -68,6 +68,9 @@ public:
GLWidget(QWidget *parent = 0);
~GLWidget();
+ static bool isTransparent() { return m_transparent; }
+ static void setTransparent(bool t) { m_transparent = t; }
+
QSize minimumSizeHint() const override;
QSize sizeHint() const override;
@@ -108,7 +111,7 @@ private:
QMatrix4x4 m_proj;
QMatrix4x4 m_camera;
QMatrix4x4 m_world;
- bool m_transparent;
+ static bool m_transparent;
};
#endif
diff --git a/examples/opengl/hellogl2/main.cpp b/examples/opengl/hellogl2/main.cpp
index 143f659eb6..b52a5a37d3 100644
--- a/examples/opengl/hellogl2/main.cpp
+++ b/examples/opengl/hellogl2/main.cpp
@@ -51,25 +51,46 @@
#include <QApplication>
#include <QDesktopWidget>
#include <QSurfaceFormat>
+#include <QCommandLineParser>
+#include <QCommandLineOption>
+#include "glwidget.h"
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
+ QCoreApplication::setApplicationName("Qt Hello GL 2 Example");
+ QCoreApplication::setOrganizationName("QtProject");
+ QCoreApplication::setApplicationVersion(QT_VERSION_STR);
+ QCommandLineParser parser;
+ parser.setApplicationDescription(QCoreApplication::applicationName());
+ parser.addHelpOption();
+ parser.addVersionOption();
+ QCommandLineOption multipleSampleOption("multisample", "Multisampling");
+ parser.addOption(multipleSampleOption);
+ QCommandLineOption coreProfileOption("coreprofile", "Use core profile");
+ parser.addOption(coreProfileOption);
+ QCommandLineOption transparentOption("transparent", "Transparent window");
+ parser.addOption(transparentOption);
+
+ parser.process(app);
+
QSurfaceFormat fmt;
fmt.setDepthBufferSize(24);
- if (QCoreApplication::arguments().contains(QStringLiteral("--multisample")))
+ if (parser.isSet(multipleSampleOption))
fmt.setSamples(4);
- if (QCoreApplication::arguments().contains(QStringLiteral("--coreprofile"))) {
+ if (parser.isSet(coreProfileOption)) {
fmt.setVersion(3, 2);
fmt.setProfile(QSurfaceFormat::CoreProfile);
}
QSurfaceFormat::setDefaultFormat(fmt);
MainWindow mainWindow;
- if (QCoreApplication::arguments().contains(QStringLiteral("--transparent"))) {
+
+ GLWidget::setTransparent(parser.isSet(transparentOption));
+ if (GLWidget::isTransparent()) {
mainWindow.setAttribute(Qt::WA_TranslucentBackground);
mainWindow.setAttribute(Qt::WA_NoSystemBackground, false);
}