An empty OpenGL window with glClearColor and glClear to fill the background with color.
6550a9c3-a2c7-4b32-8c33-cf1969283e48-image.png
QOpenGLWindow in Python:
import sys from OpenGL.GL import GL_COLOR_BUFFER_BIT, glClear, glClearColor from PySide6.QtCore import Qt from PySide6.QtOpenGL import QOpenGLWindow from PySide6.QtWidgets import QApplication class OpenGLWindow(QOpenGLWindow): def __init__(self): super().__init__() self.setTitle("OpenGL ES 2.0, PySide6, Python") self.resize(350, 350) def initializeGL(self): glClearColor(0.1, 0.3, 0.2, 1) def resizeGL(self, w, h): pass def paintGL(self): glClear(GL_COLOR_BUFFER_BIT) if __name__ == "__main__": QApplication.setAttribute(Qt.ApplicationAttribute.AA_UseDesktopOpenGL) app = QApplication(sys.argv) w = OpenGLWindow() w.show() sys.exit(app.exec())QOpenGLWidget in Python:
import sys from OpenGL.GL import GL_COLOR_BUFFER_BIT, glClear, glClearColor from PySide6.QtCore import Qt from PySide6.QtOpenGLWidgets import QOpenGLWidget from PySide6.QtWidgets import QApplication class OpenGLWidget(QOpenGLWidget): def __init__(self): super().__init__() self.setWindowTitle("OpenGL ES 2.0, PySide6, Python") self.resize(350, 350) def initializeGL(self): glClearColor(0.1, 0.3, 0.2, 1) def resizeGL(self, w, h): pass def paintGL(self): glClear(GL_COLOR_BUFFER_BIT) if __name__ == "__main__": QApplication.setAttribute(Qt.ApplicationAttribute.AA_UseDesktopOpenGL) app = QApplication(sys.argv) w = OpenGLWidget() w.show() sys.exit(app.exec())QOpenGLWindow in C++:
#include <QtGui/QOpenGLFunctions> #include <QtOpenGL/QOpenGLWindow> #include <QtWidgets/QApplication> #include <QtWidgets/QWidget> class OpenGLWindow : public QOpenGLWindow, private QOpenGLFunctions { public: OpenGLWindow() { setTitle("OpenGL ES 2.0, Qt6, C++"); resize(350, 350); } void initializeGL() override { initializeOpenGLFunctions(); glClearColor(0.1f, 0.3f, 0.2f, 1.f); } void paintGL() override { glClear(GL_COLOR_BUFFER_BIT); } }; int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::ApplicationAttribute::AA_UseDesktopOpenGL); QApplication app(argc, argv); OpenGLWindow w; w.show(); return app.exec(); } QT += core gui opengl widgets win32: LIBS += -lopengl32 CONFIG += c++17 SOURCES += \ main.cppQOpenGLWidget in C++:
#include <QtGui/QOpenGLFunctions> #include <QtOpenGLWidgets/QOpenGLWidget> #include <QtWidgets/QApplication> #include <QtWidgets/QWidget> class OpenGLWidget : public QOpenGLWidget, private QOpenGLFunctions { public: OpenGLWidget() { setWindowTitle("OpenGL ES 2.0, Qt6, C++"); resize(350, 350); } void initializeGL() override { initializeOpenGLFunctions(); glClearColor(0.1f, 0.3f, 0.2f, 1.f); } void paintGL() override { glClear(GL_COLOR_BUFFER_BIT); } }; int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::ApplicationAttribute::AA_UseDesktopOpenGL); QApplication app(argc, argv); OpenGLWidget w; w.show(); return app.exec(); } QT += core gui openglwidgets widgets win32: LIBS += -lopengl32 CONFIG += c++17 SOURCES += \ main.cpp