summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-03-30 07:38:05 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-03-30 10:31:09 +0200
commit1fb1936afb00a408799c3f8a4755da21450289b8 (patch)
tree4ae568cf34eb450da25da39f0379e92337b95740 /examples
parent52c02908abecbb9fd4afcb0de6a0b50b3ae85827 (diff)
OpenGL example: Port to QOpenGLWidget
Change-Id: I81b1b2b251a3ffca2f925d5d61f88ac71728ca2b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/activeqt/opengl/doc/src/opengl.qdoc4
-rw-r--r--examples/activeqt/opengl/glbox.cpp20
-rw-r--r--examples/activeqt/opengl/glbox.h4
-rw-r--r--examples/activeqt/opengl/main.cpp1
-rw-r--r--examples/activeqt/opengl/opengl.pro2
5 files changed, 17 insertions, 14 deletions
diff --git a/examples/activeqt/opengl/doc/src/opengl.qdoc b/examples/activeqt/opengl/doc/src/opengl.qdoc
index 5a4f8a3..000d864 100644
--- a/examples/activeqt/opengl/doc/src/opengl.qdoc
+++ b/examples/activeqt/opengl/doc/src/opengl.qdoc
@@ -82,14 +82,12 @@
\snippet activeqt/opengl/main.cpp 2
\snippet activeqt/opengl/main.cpp 3
- The \c GLBox class inherits from both the \l QGLWidget class to be able
+ The \c GLBox class inherits from both the \l QOpenGLWidget class to be able
to render OpenGL, and from \l QAxBindable.
\snippet activeqt/opengl/glbox.h 0
The class reimplements the \l QAxBindable::createAggregate() function from QAxBindable
to return the pointer to a \l QAxAggregated object.
\snippet activeqt/opengl/glbox.h 1
- The rest of the class declaration and the implementation of the OpenGL
- rendering is identical to the original "box" example.
The implementation file of the \c GLBox class includes the \c objsafe.h
system header, in which the \c IObjectSafety COM interface is defined.
diff --git a/examples/activeqt/opengl/glbox.cpp b/examples/activeqt/opengl/glbox.cpp
index 6eef79d..f9ac210 100644
--- a/examples/activeqt/opengl/glbox.cpp
+++ b/examples/activeqt/opengl/glbox.cpp
@@ -73,11 +73,18 @@
*/
GLBox::GLBox(QWidget *parent, const char *name)
- : QGLWidget(parent)
+ : QOpenGLWidget(parent)
{
m_xRot = m_yRot = m_zRot = 0.0; // default object rotation
m_scale = 1.25; // default object scale
m_object = 0;
+
+ setObjectName(name);
+
+ QSurfaceFormat format;
+ format.setVersion(1, 1);
+ format.setProfile(QSurfaceFormat::CompatibilityProfile);
+ setFormat(format);
}
@@ -122,8 +129,7 @@ void GLBox::paintGL()
void GLBox::initializeGL()
{
initializeOpenGLFunctions();
-
- qglClearColor(Qt::black); // Let OpenGL clear to black
+ glClearColor(0, 0, 0, 1); // Let OpenGL clear to black
m_object = makeObject(); // Generate an OpenGL display list
glShadeModel(GL_FLAT);
}
@@ -156,7 +162,7 @@ GLuint GLBox::makeObject()
glNewList(list, GL_COMPILE);
- qglColor(Qt::white); // Shorthand for glColor3f or glIndex
+ glColor3d(1, 1, 1); // Shorthand for glColor3f or glIndex
glLineWidth(2.0);
@@ -194,7 +200,7 @@ GLuint GLBox::makeObject()
void GLBox::setXRotation(int degrees)
{
m_xRot = (GLfloat)(degrees % 360);
- updateGL();
+ update();
}
@@ -205,7 +211,7 @@ void GLBox::setXRotation(int degrees)
void GLBox::setYRotation(int degrees)
{
m_yRot = (GLfloat)(degrees % 360);
- updateGL();
+ update();
}
@@ -216,7 +222,7 @@ void GLBox::setYRotation(int degrees)
void GLBox::setZRotation(int degrees)
{
m_zRot = (GLfloat)(degrees % 360);
- updateGL();
+ update();
}
//! [1]
diff --git a/examples/activeqt/opengl/glbox.h b/examples/activeqt/opengl/glbox.h
index b1bd828..6d73997 100644
--- a/examples/activeqt/opengl/glbox.h
+++ b/examples/activeqt/opengl/glbox.h
@@ -57,12 +57,12 @@
#ifndef GLBOX_H
#define GLBOX_H
-#include <QtOpenGL>
+#include <QOpenGLWidget>
#include <QOpenGLFunctions_1_1>
//! [0]
#include <QAxBindable>
-class GLBox : public QGLWidget,
+class GLBox : public QOpenGLWidget,
public QOpenGLFunctions_1_1,
public QAxBindable
{
diff --git a/examples/activeqt/opengl/main.cpp b/examples/activeqt/opengl/main.cpp
index 94cbf27..a3de04b 100644
--- a/examples/activeqt/opengl/main.cpp
+++ b/examples/activeqt/opengl/main.cpp
@@ -60,7 +60,6 @@
#include "globjwin.h"
#include "glbox.h"
#include <QApplication>
-#include <QtOpenGL>
//! [0]
#include <QAxFactory>
diff --git a/examples/activeqt/opengl/opengl.pro b/examples/activeqt/opengl/opengl.pro
index d3e44c4..c62f700 100644
--- a/examples/activeqt/opengl/opengl.pro
+++ b/examples/activeqt/opengl/opengl.pro
@@ -2,7 +2,7 @@ TEMPLATE = app
TARGET = openglax
CONFIG += warn_off
-QT += widgets axserver opengl
+QT += widgets axserver
HEADERS = glbox.h \
globjwin.h