diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-09-12 14:04:03 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-09-19 13:20:41 +0200 |
commit | bd180bc53ea3aa86f49070e316f965473102c383 (patch) | |
tree | 98b7de9ec1c18d65a6423aaa25e96e0e3895c56f /examples/opengl/hellogl2/main.py | |
parent | 200275225befe77d020f5caf6d8eb1a576a79755 (diff) |
Examples: Split the hellogl2 example
Some small refactoring: shorten lines, use super() and move shader
code to constants.
Refactor the transparent option handling to be in line with the C++
example.
Call the OpenGL cleanup from hideEvent() instead of
QOpenGLContext::aboutToBeDestroyed() since the signal is emitted from
the destructor and thus has no effect for Python.
Pick-to: 6.6
Task-number: PYSIDE-2460
Task-number: PYSIDE-2206
Change-Id: I5d140db6e04baf88d2ac867d809c6cff9eb740b5
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'examples/opengl/hellogl2/main.py')
-rw-r--r-- | examples/opengl/hellogl2/main.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/examples/opengl/hellogl2/main.py b/examples/opengl/hellogl2/main.py new file mode 100644 index 000000000..ea35c0077 --- /dev/null +++ b/examples/opengl/hellogl2/main.py @@ -0,0 +1,59 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# Copyright (C) 2013 Riverbank Computing Limited. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +"""PySide6 port of the opengl/hellogl2 example from Qt v6.x""" + +from argparse import ArgumentParser, RawTextHelpFormatter +import sys +from PySide6.QtCore import Qt +from PySide6.QtGui import QSurfaceFormat +from PySide6.QtWidgets import (QApplication, QMessageBox) + + +try: + from window import Window + from glwidget import GLWidget +except ImportError: + app = QApplication(sys.argv) + message_box = QMessageBox(QMessageBox.Critical, "OpenGL hellogl", + "PyOpenGL must be installed to run this example.", + QMessageBox.Close) + message_box.setDetailedText("Run:\npip install PyOpenGL PyOpenGL_accelerate") + message_box.exec() + sys.exit(1) + + +if __name__ == '__main__': + app = QApplication(sys.argv) + parser = ArgumentParser(description="hellogl2", + formatter_class=RawTextHelpFormatter) + parser.add_argument('--multisample', '-m', action='store_true', + help='Use Multisampling') + parser.add_argument('--coreprofile', '-c', action='store_true', + help='Use Core Profile') + parser.add_argument('--transparent', '-t', action='store_true', + help='Transparent Windows') + options = parser.parse_args() + + fmt = QSurfaceFormat() + fmt.setDepthBufferSize(24) + if options.multisample: + fmt.setSamples(4) + if options.coreprofile: + fmt.setVersion(3, 2) + fmt.setProfile(QSurfaceFormat.CoreProfile) + QSurfaceFormat.setDefaultFormat(fmt) + + GLWidget.set_transparent(options.transparent) + + main_window = Window() + if options.transparent: + main_window.setAttribute(Qt.WA_TranslucentBackground) + main_window.setAttribute(Qt.WA_NoSystemBackground, False) + + main_window.resize(main_window.sizeHint()) + main_window.show() + + res = app.exec() + sys.exit(res) |