summaryrefslogtreecommitdiffstats
path: root/tests/manual/examples/opengl/qopenglwidget/glwidget.h
blob: de9d11b94c28b34350406163a14335814e99bd4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLBuffer>
#include <QVector3D>
#include <QMatrix4x4>
#include <QElapsedTimer>
#include <QList>
#include <QPushButton>

class Bubble;
class MainWindow;

QT_FORWARD_DECLARE_CLASS(QOpenGLTexture)
QT_FORWARD_DECLARE_CLASS(QOpenGLShader)
QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram)

class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
    Q_OBJECT
public:
    GLWidget(MainWindow *maybeMainWindow, const QColor &background);
    ~GLWidget();

public slots:
    void setScaling(int scale);
    void setLogo();
    void setTexture();
    void setShowBubbles(bool);
    void setTransparent(bool transparent);

protected:
    void resizeGL(int w, int h) override;
    void paintGL() override;
    void initializeGL() override;

private:
    void paintTexturedCube();
    void paintQtLogo();
    void createGeometry();
    void createBubbles(int number);
    void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4);
    void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
    void reset();

    MainWindow *m_mainWindow;
    qreal m_fAngle = 0;
    qreal m_fScale = 1;
    bool m_showBubbles = true;
    QList<QVector3D> m_vertices;
    QList<QVector3D> m_normals;
    bool m_qtLogo = true;
    QList<Bubble *> m_bubbles;
    int m_frames = 0;
    QElapsedTimer m_time;
    QOpenGLShader *m_vshader1 = nullptr;
    QOpenGLShader *m_fshader1 = nullptr;
    QOpenGLShader *m_vshader2 = nullptr;
    QOpenGLShader *m_fshader2 = nullptr;
    QOpenGLShaderProgram *m_program1 = nullptr;
    QOpenGLShaderProgram *m_program2 = nullptr;
    QOpenGLTexture *m_texture = nullptr;
    QOpenGLBuffer m_vbo1;
    QOpenGLBuffer m_vbo2;
    int m_vertexAttr1 = 0;
    int m_normalAttr1 = 0;
    int m_matrixUniform1 = 0;
    int m_vertexAttr2 = 0;
    int m_normalAttr2 = 0;
    int m_texCoordAttr2 = 0;
    int m_matrixUniform2 = 0;
    int m_textureUniform2 = 0;
    bool m_transparent = false;
    QPushButton *m_btn = nullptr;
    QPushButton *m_btn2 = nullptr;
    QColor m_background;
    QMetaObject::Connection m_contextWatchConnection;
};

#endif