| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause |
| 3 |
|
| 4 |
#ifndef GLWIDGET_H |
| 5 |
#define GLWIDGET_H |
| 6 |
|
| 7 |
#include <QOpenGLWidget> |
| 8 |
#include <QOpenGLFunctions> |
| 9 |
#include <QOpenGLBuffer> |
| 10 |
#include <QVector3D> |
| 11 |
#include <QMatrix4x4> |
| 12 |
#include <QElapsedTimer> |
| 13 |
#include <QList> |
| 14 |
#include <QPushButton> |
| 15 |
|
| 16 |
class Bubble; |
| 17 |
class MainWindow; |
| 18 |
|
| 19 |
QT_FORWARD_DECLARE_CLASS(QOpenGLTexture) |
| 20 |
QT_FORWARD_DECLARE_CLASS(QOpenGLShader) |
| 21 |
QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram) |
| 22 |
|
| 23 |
class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions |
| 24 |
{ |
| 25 |
Q_OBJECT |
| 26 |
public: |
| 27 |
GLWidget(MainWindow *maybeMainWindow, const QColor &background); |
| 28 |
~GLWidget(); |
| 29 |
|
| 30 |
public slots: |
| 31 |
void setScaling(int scale); |
| 32 |
void setLogo(); |
| 33 |
void setTexture(); |
| 34 |
void setShowBubbles(bool); |
| 35 |
void setTransparent(bool transparent); |
| 36 |
|
| 37 |
protected: |
| 38 |
void resizeGL(int w, int h) override; |
| 39 |
void paintGL() override; |
| 40 |
void initializeGL() override; |
| 41 |
|
| 42 |
private: |
| 43 |
void paintTexturedCube(); |
| 44 |
void paintQtLogo(); |
| 45 |
void createGeometry(); |
| 46 |
void createBubbles(int number); |
| 47 |
void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4); |
| 48 |
void extrude(qreal x1, qreal y1, qreal x2, qreal y2); |
| 49 |
void reset(); |
| 50 |
|
| 51 |
MainWindow *m_mainWindow; |
| 52 |
qreal m_fAngle = 0; |
| 53 |
qreal m_fScale = 1; |
| 54 |
bool m_showBubbles = true; |
| 55 |
QList<QVector3D> m_vertices; |
| 56 |
QList<QVector3D> m_normals; |
| 57 |
bool m_qtLogo = true; |
| 58 |
QList<Bubble *> m_bubbles; |
| 59 |
int m_frames = 0; |
| 60 |
QElapsedTimer m_time; |
| 61 |
QOpenGLShader *m_vshader1 = nullptr; |
| 62 |
QOpenGLShader *m_fshader1 = nullptr; |
| 63 |
QOpenGLShader *m_vshader2 = nullptr; |
| 64 |
QOpenGLShader *m_fshader2 = nullptr; |
| 65 |
QOpenGLShaderProgram *m_program1 = nullptr; |
| 66 |
QOpenGLShaderProgram *m_program2 = nullptr; |
| 67 |
QOpenGLTexture *m_texture = nullptr; |
| 68 |
QOpenGLBuffer m_vbo1; |
| 69 |
QOpenGLBuffer m_vbo2; |
| 70 |
int m_vertexAttr1 = 0; |
| 71 |
int m_normalAttr1 = 0; |
| 72 |
int m_matrixUniform1 = 0; |
| 73 |
int m_vertexAttr2 = 0; |
| 74 |
int m_normalAttr2 = 0; |
| 75 |
int m_texCoordAttr2 = 0; |
| 76 |
int m_matrixUniform2 = 0; |
| 77 |
int m_textureUniform2 = 0; |
| 78 |
bool m_transparent = false; |
| 79 |
QPushButton *m_btn = nullptr; |
| 80 |
QPushButton *m_btn2 = nullptr; |
| 81 |
QColor m_background; |
| 82 |
QMetaObject::Connection m_contextWatchConnection; |
| 83 |
}; |
| 84 |
|
| 85 |
#endif |