2011-04-27 15:49:30 +00:00
|
|
|
#include <QWindow>
|
|
|
|
|
|
|
|
#include <QtOpenGL/qgl.h>
|
|
|
|
#include <QtOpenGL/qglshaderprogram.h>
|
2011-08-18 08:50:18 +00:00
|
|
|
#include <QtOpenGL/qglframebufferobject.h>
|
2011-04-27 15:49:30 +00:00
|
|
|
|
|
|
|
#include <QTime>
|
|
|
|
|
2011-06-07 15:25:22 +00:00
|
|
|
class QGuiGLContext;
|
|
|
|
|
|
|
|
class Renderer : public QObject
|
2011-04-27 15:49:30 +00:00
|
|
|
{
|
2011-08-18 08:50:18 +00:00
|
|
|
Q_OBJECT
|
2011-04-27 15:49:30 +00:00
|
|
|
public:
|
2011-08-18 08:50:18 +00:00
|
|
|
Renderer(const QSurfaceFormat &format, Renderer *share = 0);
|
2011-04-27 15:49:30 +00:00
|
|
|
|
2011-08-18 08:50:18 +00:00
|
|
|
QSurfaceFormat format() const { return m_format; }
|
2011-04-27 15:49:30 +00:00
|
|
|
|
2011-08-18 08:50:18 +00:00
|
|
|
public slots:
|
2011-06-21 11:39:26 +00:00
|
|
|
void render(QSurface *surface, const QColor &color, const QSize &viewSize);
|
2011-04-27 15:49:30 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void initialize();
|
|
|
|
|
2011-04-27 15:52:51 +00:00
|
|
|
qreal m_fAngle;
|
2011-04-27 15:49:30 +00:00
|
|
|
bool m_showBubbles;
|
|
|
|
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);
|
|
|
|
QVector<QVector3D> vertices;
|
|
|
|
QVector<QVector3D> normals;
|
|
|
|
QGLShaderProgram program;
|
|
|
|
int vertexAttr;
|
|
|
|
int normalAttr;
|
|
|
|
int matrixUniform;
|
|
|
|
int colorUniform;
|
2011-06-07 15:25:22 +00:00
|
|
|
|
|
|
|
bool m_initialized;
|
2011-06-21 11:39:26 +00:00
|
|
|
QSurfaceFormat m_format;
|
2011-06-07 15:25:22 +00:00
|
|
|
QGuiGLContext *m_context;
|
|
|
|
};
|
|
|
|
|
|
|
|
class HelloWindow : public QWindow
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
HelloWindow(Renderer *renderer);
|
|
|
|
|
2011-08-18 08:50:18 +00:00
|
|
|
void updateColor();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void needRender(QSurface *surface, const QColor &color, const QSize &viewSize);
|
|
|
|
|
2011-06-07 15:25:22 +00:00
|
|
|
private slots:
|
|
|
|
void render();
|
|
|
|
|
|
|
|
private:
|
2011-08-18 08:50:18 +00:00
|
|
|
void mousePressEvent(QMouseEvent *);
|
2011-06-07 15:25:22 +00:00
|
|
|
|
|
|
|
int m_colorIndex;
|
|
|
|
QColor m_color;
|
|
|
|
Renderer *m_renderer;
|
2011-04-27 15:49:30 +00:00
|
|
|
};
|