-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwidget.h
149 lines (126 loc) · 3.47 KB
/
widget.h
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QGLWidget>
#include <QVector>
#include <QVector3D>
//#include <GL/gl.h>
#include <GL/glu.h>
#include <cmath>
#include <QPoint>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QDebug>
#include <QGLFunctions>
#include <QTimer>
#include <QDesktopWidget>
#include <QOpenGLWidget>
#include <QOpenGLTexture>
#include <QOpenGLFunctions>
#include <QMatrix4x4>
#include <QOpenGLShaderProgram>
#include <QGLShader>
#include <QOpenGLFunctions_3_3_Core>
#include <QOpenGLExtraFunctions>
//#include <GL/glext.h>
//#include <GLES3/gl3.h>
//#include <QOpenGLWidget>
#define PI 3.1415926
namespace Ui {
class Widget;
}
struct Face
{
int v[3];
int t[3];
int n[3];
};
class Texture : public QGLWidget,protected QGLFunctions
{
public:
static void loadTexture(QString filepath, GLuint *texture)
{
QImage tex, buf;
if(!buf.load(filepath))
{
qDebug()<<"Error: failed to load image!";
exit(1);
}
tex = convertToGLFormat(buf);
glGenTextures(1, texture);
glBindTexture(GL_TEXTURE_2D, *texture);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, tex.width(), tex.height(), GL_RGBA, GL_UNSIGNED_BYTE, tex.bits());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL,3);
}
static void loadTexture(QOpenGLTexture *&texture, const QString &img)
{
glEnable(GL_TEXTURE_2D);
texture = new QOpenGLTexture(QImage(img));
texture->setMinificationFilter(QOpenGLTexture::Linear);
texture->setMagnificationFilter(QOpenGLTexture::Linear);
}
};
class Widget : public QOpenGLWidget,protected QOpenGLFunctions
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
void BuildVase(int v_levels, int h_levels);
void BuildBall(int R, int split_v, int split_h, QVector3D positon = QVector3D(0,0,0));
void drawBall(QVector3D position= QVector3D(0,0,0));
void drawVase();
void setRadius(float r);
//void drawObj();
QVector3D cross(QVector3D a, QVector3D b);
void mouseMoveEvent(QMouseEvent *e);
void mousePressEvent(QMouseEvent *e);
void wheelEvent(QWheelEvent *e);
QOpenGLShaderProgram *program;
QOpenGLShaderProgram *depthShader;
GLuint *depthMapFBO;
GLuint *depthMap;
QMatrix4x4 Projection,Model,View;
void makeshader();
QOpenGLTexture* texture0,*texture1;
QVector<QVector3D> m_vertexs;
QVector<QVector3D> m_texcoords;
QVector<QVector3D> m_normals;
void init();
void stop();
void start(int fps);
GLdouble *vertexs;
GLdouble *texcoords;
GLdouble *normals;
GLuint *tex0;//纹理
GLuint *tex1;//纹理
float horizontal;
float vertical;
float dist;
QPoint m_last;
void setHeight(int value);
void setLossrate(float value);
void setV0(float value);
void setTime();
void RenderCube();
public slots:
void updateScane();
private:
void genDepthMap(GLuint *&depthMapFBO,GLuint *&depthMap,GLuint SHADOW_WIDTH,GLuint SHADOW_HEIGHT);
float time;
float v0;
float cur_v;
float radius;
float max_height;
float lossrate;
QVector3D curPos;
QTimer *fps;
int ballHeight;
QOpenGLFunctions_3_3_Core * core;
Ui::Widget *ui;
};
#endif // WIDGET_H