Make OpenGL legacy examples hellogl and overpainting work with Dynamic GL.
Call GL functions using QOpenGLFunctions_1_1. Task-number: QTBUG-46103 Change-Id: I1cbacf9c192c17d96d96aa861bb16e2918a0c053 Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
This commit is contained in:
parent
4476966e04
commit
cab7e7858a
@ -128,6 +128,8 @@ void GLWidget::setZRotation(int angle)
|
||||
//! [6]
|
||||
void GLWidget::initializeGL()
|
||||
{
|
||||
initializeOpenGLFunctions();
|
||||
|
||||
qglClearColor(qtPurple.dark());
|
||||
|
||||
logo = new QtLogo(this, 64);
|
||||
@ -153,7 +155,7 @@ void GLWidget::paintGL()
|
||||
glRotatef(xRot / 16.0, 1.0, 0.0, 0.0);
|
||||
glRotatef(yRot / 16.0, 0.0, 1.0, 0.0);
|
||||
glRotatef(zRot / 16.0, 0.0, 0.0, 1.0);
|
||||
logo->draw();
|
||||
logo->draw(static_cast<QOpenGLFunctions_1_1 *>(this));
|
||||
}
|
||||
//! [7]
|
||||
|
||||
|
@ -42,11 +42,12 @@
|
||||
#define GLWIDGET_H
|
||||
|
||||
#include <QGLWidget>
|
||||
#include <QOpenGLFunctions_1_1>
|
||||
|
||||
class QtLogo;
|
||||
|
||||
//! [0]
|
||||
class GLWidget : public QGLWidget
|
||||
class GLWidget : public QGLWidget, public QOpenGLFunctions_1_1
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -14,4 +14,4 @@ QT += opengl widgets
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/opengl/legacy/hellogl
|
||||
INSTALLS += target
|
||||
|
||||
contains(QT_CONFIG, opengles.|angle|dynamicgl):error("This example requires Qt to be configured with -opengl desktop")
|
||||
contains(QT_CONFIG, opengles.|angle):error("This example requires Qt to be configured with -opengl desktop")
|
||||
|
@ -115,6 +115,8 @@ void GLWidget::setZRotation(int angle)
|
||||
//! [2]
|
||||
void GLWidget::initializeGL()
|
||||
{
|
||||
initializeOpenGLFunctions();
|
||||
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
|
||||
logo = new QtLogo(this);
|
||||
@ -173,7 +175,7 @@ void GLWidget::paintEvent(QPaintEvent *event)
|
||||
glRotatef(yRot / 16.0, 0.0, 1.0, 0.0);
|
||||
glRotatef(zRot / 16.0, 0.0, 0.0, 1.0);
|
||||
|
||||
logo->draw();
|
||||
logo->draw(static_cast<QOpenGLFunctions_1_1 *>(this));
|
||||
//! [7]
|
||||
|
||||
//! [8]
|
||||
|
@ -42,13 +42,14 @@
|
||||
#define GLWIDGET_H
|
||||
|
||||
#include <QGLWidget>
|
||||
#include <QOpenGLFunctions_1_1>
|
||||
#include <QTimer>
|
||||
|
||||
class Bubble;
|
||||
class QtLogo;
|
||||
|
||||
//! [0]
|
||||
class GLWidget : public QGLWidget
|
||||
class GLWidget : public QGLWidget, public QOpenGLFunctions_1_1
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -16,4 +16,4 @@ SOURCES = bubble.cpp \
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/opengl/legacy/overpainting
|
||||
INSTALLS += target
|
||||
|
||||
contains(QT_CONFIG, opengles.|angle|dynamicgl):error("This example requires Qt to be configured with -opengl desktop")
|
||||
contains(QT_CONFIG, opengles.|angle):error("This example requires Qt to be configured with -opengl desktop")
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include <QGLWidget>
|
||||
#include <QMatrix4x4>
|
||||
#include <QVector3D>
|
||||
#include <QOpenGLFunctions_1_1>
|
||||
|
||||
#include <qmath.h>
|
||||
|
||||
@ -60,7 +61,7 @@ struct Geometry
|
||||
void appendSmooth(const QVector3D &a, const QVector3D &n, int from);
|
||||
void appendFaceted(const QVector3D &a, const QVector3D &n);
|
||||
void finalize();
|
||||
void loadArrays() const;
|
||||
void loadArrays(QOpenGLFunctions_1_1 *functions) const;
|
||||
};
|
||||
//! [0]
|
||||
|
||||
@ -73,7 +74,7 @@ public:
|
||||
void setSmoothing(Smoothing s) { sm = s; }
|
||||
void translate(const QVector3D &t);
|
||||
void rotate(qreal deg, QVector3D axis);
|
||||
void draw() const;
|
||||
void draw(QOpenGLFunctions_1_1 *functions) const;
|
||||
void addTri(const QVector3D &a, const QVector3D &b, const QVector3D &c, const QVector3D &n);
|
||||
void addQuad(const QVector3D &a, const QVector3D &b, const QVector3D &c, const QVector3D &d);
|
||||
|
||||
@ -96,10 +97,10 @@ static inline void qSetColor(float colorVec[], QColor c)
|
||||
colorVec[3] = c.alphaF();
|
||||
}
|
||||
|
||||
void Geometry::loadArrays() const
|
||||
void Geometry::loadArrays(QOpenGLFunctions_1_1 *functions) const
|
||||
{
|
||||
glVertexPointer(3, GL_FLOAT, 0, vertices.constData());
|
||||
glNormalPointer(GL_FLOAT, 0, normals.constData());
|
||||
functions->glVertexPointer(3, GL_FLOAT, 0, vertices.constData());
|
||||
functions->glNormalPointer(GL_FLOAT, 0, normals.constData());
|
||||
}
|
||||
|
||||
void Geometry::finalize()
|
||||
@ -170,15 +171,15 @@ void Patch::translate(const QVector3D &t)
|
||||
}
|
||||
|
||||
//! [2]
|
||||
void Patch::draw() const
|
||||
void Patch::draw(QOpenGLFunctions_1_1 *functions) const
|
||||
{
|
||||
glPushMatrix();
|
||||
glMultMatrixf(mat.constData());
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, faceColor);
|
||||
functions->glPushMatrix();
|
||||
functions->glMultMatrixf(mat.constData());
|
||||
functions->glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, faceColor);
|
||||
|
||||
const GLushort *indices = geom->faces.constData();
|
||||
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, indices + start);
|
||||
glPopMatrix();
|
||||
functions->glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, indices + start);
|
||||
functions->glPopMatrix();
|
||||
}
|
||||
//! [2]
|
||||
|
||||
@ -371,17 +372,17 @@ void QtLogo::buildGeometry(int divisions, qreal scale)
|
||||
//! [3]
|
||||
|
||||
//! [4]
|
||||
void QtLogo::draw() const
|
||||
void QtLogo::draw(QOpenGLFunctions_1_1 *functions) const
|
||||
{
|
||||
geom->loadArrays();
|
||||
geom->loadArrays(functions);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_NORMAL_ARRAY);
|
||||
functions->glEnableClientState(GL_VERTEX_ARRAY);
|
||||
functions->glEnableClientState(GL_NORMAL_ARRAY);
|
||||
|
||||
for (int i = 0; i < parts.count(); ++i)
|
||||
parts[i]->draw();
|
||||
parts[i]->draw(functions);
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
functions->glDisableClientState(GL_VERTEX_ARRAY);
|
||||
functions->glDisableClientState(GL_NORMAL_ARRAY);
|
||||
}
|
||||
//! [4]
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include <QObject>
|
||||
#include <QColor>
|
||||
|
||||
class QOpenGLFunctions_1_1;
|
||||
class Patch;
|
||||
struct Geometry;
|
||||
|
||||
@ -54,7 +55,7 @@ public:
|
||||
explicit QtLogo(QObject *parent, int d = 64, qreal s = 1.0);
|
||||
~QtLogo();
|
||||
void setColor(QColor c);
|
||||
void draw() const;
|
||||
void draw(QOpenGLFunctions_1_1 *functions) const;
|
||||
private:
|
||||
void buildGeometry(int d, qreal s);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user