From 6a66f29ead9cd354c6da542358eb82c2519b10c5 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 8 Jun 2012 11:18:18 +0100 Subject: [PATCH] OpenGL: Update QOpenGLFunctions docs to remove widget code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I4246a49444c09d899f2bd7cd2e9353ee0a6859bf Reviewed-by: Samuel Rødal --- src/gui/opengl/qopenglfunctions.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/gui/opengl/qopenglfunctions.cpp b/src/gui/opengl/qopenglfunctions.cpp index c2e177c162..f19d4735e1 100644 --- a/src/gui/opengl/qopenglfunctions.cpp +++ b/src/gui/opengl/qopenglfunctions.cpp @@ -64,19 +64,37 @@ QT_BEGIN_NAMESPACE direct inheritance: \code - class MyGLWidget : public QOpenGLWidget, protected QOpenGLFunctions + class MyGLWindow : public QWindow, protected QOpenGLFunctions { Q_OBJECT public: - MyGLWidget(QWidget *parent = 0) : QOpenGLWidget(parent) {} + MyGLWindow(QScreen *screen = 0); protected: void initializeGL(); void paintGL(); + + QOpenGLContext *m_context; }; - void MyGLWidget::initializeGL() + MyGLWindow(QScreen *screen) + : QWindow(screen), QOpenGLWidget(parent) { + setSurfaceType(OpenGLSurface); + create(); + + // Create an OpenGL context + m_context = new QOpenGLContext; + m_context->create(); + + // Setup scene and render it + initializeGL(); + paintGL() + } + + void MyGLWindow::initializeGL() + { + m_context->makeCurrent(this); initializeGLFunctions(); } \endcode @@ -86,11 +104,14 @@ QT_BEGIN_NAMESPACE in the following example: \code - void MyGLWidget::paintGL() + void MyGLWindow::paintGL() { + m_context->makeCurrent(this); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textureId); ... + m_context->swapBuffers(this); + m_context->doneCurrent(); } \endcode