| 1 |
// Copyright (C) 2022 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 |
|
| 17 |
QT_FORWARD_DECLARE_CLASS(QOpenGLTexture) |
| 18 |
QT_FORWARD_DECLARE_CLASS(QOpenGLShader) |
| 19 |
QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram) |
| 20 |
|
| 21 |
class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions |
| 22 |
{ |
| 23 |
Q_OBJECT |
| 24 |
public: |
| 25 |
GLWidget(const QColor &background); |
| 26 |
~GLWidget(); |
| 27 |
|
| 28 |
void saveImage(QOpenGLWidget::TargetBuffer targetBuffer); |
| 29 |
|
| 30 |
protected: |
| 31 |
void paintGL() override; |
| 32 |
void initializeGL() override; |
| 33 |
|
| 34 |
private: |
| 35 |
void createGeometry(); |
| 36 |
void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4); |
| 37 |
void extrude(qreal x1, qreal y1, qreal x2, qreal y2); |
| 38 |
void reset(); |
| 39 |
|
| 40 |
QList<QVector3D> m_vertices; |
| 41 |
QList<QVector3D> m_normals; |
| 42 |
QOpenGLShader *m_vshader = nullptr; |
| 43 |
QOpenGLShader *m_fshader = nullptr; |
| 44 |
QOpenGLShaderProgram *m_program = nullptr; |
| 45 |
QOpenGLBuffer m_vbo; |
| 46 |
int m_vertexAttr; |
| 47 |
int m_normalAttr; |
| 48 |
int m_matrixUniform; |
| 49 |
QColor m_background; |
| 50 |
QMetaObject::Connection m_contextWatchConnection; |
| 51 |
}; |
| 52 |
|
| 53 |
#endif |