diff options
Diffstat (limited to 'examples/opengl')
-rw-r--r-- | examples/opengl/legacy/hellogl/glwidget.cpp | 4 | ||||
-rw-r--r-- | examples/opengl/legacy/hellogl/glwidget.h | 3 | ||||
-rw-r--r-- | examples/opengl/legacy/hellogl/hellogl.pro | 2 | ||||
-rw-r--r-- | examples/opengl/legacy/overpainting/glwidget.cpp | 4 | ||||
-rw-r--r-- | examples/opengl/legacy/overpainting/glwidget.h | 3 | ||||
-rw-r--r-- | examples/opengl/legacy/overpainting/overpainting.pro | 2 | ||||
-rw-r--r-- | examples/opengl/legacy/shared/qtlogo.cpp | 37 | ||||
-rw-r--r-- | examples/opengl/legacy/shared/qtlogo.h | 3 | ||||
-rw-r--r-- | examples/opengl/qopenglwidget/glwidget.cpp | 6 | ||||
-rw-r--r-- | examples/opengl/qopenglwidget/mainwindow.cpp | 20 | ||||
-rw-r--r-- | examples/opengl/qopenglwidget/mainwindow.h | 2 |
11 files changed, 54 insertions, 32 deletions
diff --git a/examples/opengl/legacy/hellogl/glwidget.cpp b/examples/opengl/legacy/hellogl/glwidget.cpp index 02501cd99e..122f7ddfe1 100644 --- a/examples/opengl/legacy/hellogl/glwidget.cpp +++ b/examples/opengl/legacy/hellogl/glwidget.cpp @@ -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] diff --git a/examples/opengl/legacy/hellogl/glwidget.h b/examples/opengl/legacy/hellogl/glwidget.h index 994e38e13d..9aca4451df 100644 --- a/examples/opengl/legacy/hellogl/glwidget.h +++ b/examples/opengl/legacy/hellogl/glwidget.h @@ -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 diff --git a/examples/opengl/legacy/hellogl/hellogl.pro b/examples/opengl/legacy/hellogl/hellogl.pro index bb75b07200..c211242fd2 100644 --- a/examples/opengl/legacy/hellogl/hellogl.pro +++ b/examples/opengl/legacy/hellogl/hellogl.pro @@ -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") diff --git a/examples/opengl/legacy/overpainting/glwidget.cpp b/examples/opengl/legacy/overpainting/glwidget.cpp index b41bc31126..52b6c35801 100644 --- a/examples/opengl/legacy/overpainting/glwidget.cpp +++ b/examples/opengl/legacy/overpainting/glwidget.cpp @@ -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] diff --git a/examples/opengl/legacy/overpainting/glwidget.h b/examples/opengl/legacy/overpainting/glwidget.h index dd5c0ba9ff..7e62a00170 100644 --- a/examples/opengl/legacy/overpainting/glwidget.h +++ b/examples/opengl/legacy/overpainting/glwidget.h @@ -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 diff --git a/examples/opengl/legacy/overpainting/overpainting.pro b/examples/opengl/legacy/overpainting/overpainting.pro index cbed7eed2b..cc46f18889 100644 --- a/examples/opengl/legacy/overpainting/overpainting.pro +++ b/examples/opengl/legacy/overpainting/overpainting.pro @@ -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") diff --git a/examples/opengl/legacy/shared/qtlogo.cpp b/examples/opengl/legacy/shared/qtlogo.cpp index efe3fb0201..0d960dd4b6 100644 --- a/examples/opengl/legacy/shared/qtlogo.cpp +++ b/examples/opengl/legacy/shared/qtlogo.cpp @@ -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] diff --git a/examples/opengl/legacy/shared/qtlogo.h b/examples/opengl/legacy/shared/qtlogo.h index 562435daed..9bd15a1431 100644 --- a/examples/opengl/legacy/shared/qtlogo.h +++ b/examples/opengl/legacy/shared/qtlogo.h @@ -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); diff --git a/examples/opengl/qopenglwidget/glwidget.cpp b/examples/opengl/qopenglwidget/glwidget.cpp index f93e667615..df52e3efbf 100644 --- a/examples/opengl/qopenglwidget/glwidget.cpp +++ b/examples/opengl/qopenglwidget/glwidget.cpp @@ -537,14 +537,14 @@ void GLWidget::setTransparent(bool transparent) window()->update(); } -void GLWidget::resizeGL(int w, int h) +void GLWidget::resizeGL(int, int) { if (m_hasButton) { if (!m_btn) { - m_btn = new QPushButton("A widget on top.\nPress me!", this); + m_btn = new QPushButton("A widget on top.\nPress for more widgets.", this); connect(m_btn, &QPushButton::clicked, this, &GLWidget::handleButtonPress); } - m_btn->move(w / 2, h / 2); + m_btn->move(20, 80); } } diff --git a/examples/opengl/qopenglwidget/mainwindow.cpp b/examples/opengl/qopenglwidget/mainwindow.cpp index 6cf1d5d6e2..22111afdcb 100644 --- a/examples/opengl/qopenglwidget/mainwindow.cpp +++ b/examples/opengl/qopenglwidget/mainwindow.cpp @@ -47,6 +47,7 @@ #include <QLabel> #include <QCheckBox> #include <QSpinBox> +#include <QScrollArea> #include "glwidget.h" @@ -69,7 +70,7 @@ MainWindow::MainWindow() "and therefore an interval < 16 ms will likely lead to a 60 FPS update rate."); QGroupBox *updateGroupBox = new QGroupBox(this); QCheckBox *timerBased = new QCheckBox("Use timer", this); - timerBased->setChecked(true); + timerBased->setChecked(false); timerBased->setToolTip("Toggles using a timer to trigger update().\n" "When not set, each paintGL() schedules the next update immediately,\n" "expecting the blocking swap to throttle the thread.\n" @@ -87,7 +88,7 @@ MainWindow::MainWindow() slider->setRange(0, 50); slider->setSliderPosition(30); m_timer->setInterval(10); - label->setText("A QOpenGLWidget"); + label->setText("A scrollable QOpenGLWidget"); label->setAlignment(Qt::AlignHCenter); QGroupBox * groupBox = new QGroupBox(this); @@ -96,7 +97,10 @@ MainWindow::MainWindow() m_layout = new QGridLayout(groupBox); - m_layout->addWidget(glwidget,1,0,8,1); + QScrollArea *scrollArea = new QScrollArea; + scrollArea->setWidget(glwidget); + + m_layout->addWidget(scrollArea,1,0,8,1); m_layout->addWidget(label,9,0,1,1); m_layout->addWidget(updateGroupBox, 10, 0, 1, 1); m_layout->addWidget(slider, 11,0,1,1); @@ -134,7 +138,10 @@ MainWindow::MainWindow() connect(timerBased, &QCheckBox::toggled, this, &MainWindow::timerUsageChanged); connect(timerBased, &QCheckBox::toggled, updateInterval, &QWidget::setEnabled); - m_timer->start(); + if (timerBased->isChecked()) + m_timer->start(); + else + updateInterval->setEnabled(false); } void MainWindow::updateIntervalChanged(int value) @@ -170,3 +177,8 @@ void MainWindow::timerUsageChanged(bool enabled) w->update(); } } + +void MainWindow::resizeEvent(QResizeEvent *) +{ + m_glWidgets[0]->setMinimumSize(size() + QSize(128, 128)); +} diff --git a/examples/opengl/qopenglwidget/mainwindow.h b/examples/opengl/qopenglwidget/mainwindow.h index f1b2c51e53..9ad8a01339 100644 --- a/examples/opengl/qopenglwidget/mainwindow.h +++ b/examples/opengl/qopenglwidget/mainwindow.h @@ -56,6 +56,8 @@ public: void addNew(); bool timerEnabled() const { return m_timer->isActive(); } + void resizeEvent(QResizeEvent *); + private slots: void updateIntervalChanged(int value); void timerUsageChanged(bool enabled); |