-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopenglitem.h
257 lines (186 loc) · 6.72 KB
/
openglitem.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#ifndef OPENGLITEM_H
#define OPENGLITEM_H
#include <iostream>
#include <QQuickItem>
#include <QQuickFramebufferObject>
#include <QOpenGLFramebufferObjectFormat>
#include <QOpenGLFunctions>
#include <QOpenGLTexture>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLBuffer>
#include <QOpenGLShaderProgram>
#include <QVector3D>
#include <QQuickWindow>
#include <QKeyEvent>
#include <QTimer>
#include <QElapsedTimer>
#include <QPointF>
#include <QSet>
#include <QFileSystemModel>
#include <camera.h>
#include <shader.h>
#include <light.h>
#include <qml_camera.h>
#include <qml_light.h>
#include <qml_generalData.h>
#include <filesystem.h>
#include <sandboxitemmodel.h>
#include "model.h"
#include "terrain.h"
class CustomItemRenderer : public QQuickFramebufferObject::Renderer
{
public:
CustomItemRenderer();
~CustomItemRenderer();
private:
virtual void render();
void initialize();
virtual QOpenGLFramebufferObject * createFramebufferObject(const QSize & size);
virtual void synchronize(QQuickFramebufferObject *item);
private: //model infos
QOpenGLTexture *modelTextures[2] = {nullptr, nullptr}; // diffuseMap, specularMap
GLuint textureIDs[1]; // emissionMap
private:
QQuickWindow *m_Window = nullptr; //pointing to mainWindow(GUI)
Shader* shader;
Shader* shaderLight;
QSharedPointer<Shader> shaderTerrainHq, shaderTerrainMq, shaderTerrainLq;
Camera *camera;
Light *light;
Qml_light* light_qml;
Qml_generalData* generalData_qml;
FileSystem* fileSystem;
QVector3D lightPos;
QList<QSharedPointer<Model>> modelList;
QList<QSharedPointer<Terrain>> terrainList;
void drawObject();
QOpenGLFunctions *ogl;
QMatrix4x4 m_projection;
QTimer *qTimer; //start(int msec) msec sonra bir fonksiyon çalıştıraiblir bunun için QObject::connect ile signal belli bir slot'a atanır.
QElapsedTimer *timer; //start, restart, elapsed, invalidate(isValid kontrolü yap)
private:
bool firstSynchronize = true;
bool firstRender = true;
//keyboard, mouse io's
float deltaTime = 0.0f;
float lastFrame = 0.0f;
float currentFrame = 0.0f;
QList<GLenum> depthFuncs = {0, GL_LESS, GL_ALWAYS, GL_NEVER, GL_EQUAL, GL_LEQUAL, GL_GREATER, GL_NOTEQUAL, GL_GEQUAL};
};
class CustomItemBase : public QQuickFramebufferObject
{
Q_OBJECT
Q_PROPERTY(Qml_camera* cam READ cam CONSTANT)
Q_PROPERTY(Qml_light* light READ light CONSTANT)
Q_PROPERTY(Qml_generalData* generalData READ generalData CONSTANT)
Q_PROPERTY(QFileSystemModel* fileSystem READ fileSystem CONSTANT)
Q_PROPERTY(SandBoxItemModel* fileSystemNew READ fileSystemNew CONSTANT)
//properties für qml
public:
Qml_camera *cam() const{
return m_qmlCamera;
}
Qml_light *light() const{
return m_qmlLight;
}
Qml_generalData* generalData() const{
return m_qmlGeneralData;
}
QFileSystemModel* fileSystem() const {
return m_fileSystem;
}
SandBoxItemModel* fileSystemNew() const {
return m_fileSystemNew;
}
private:
QPointer<Qml_camera> m_qmlCamera;
QPointer<Qml_light> m_qmlLight;
QPointer<Qml_generalData> m_qmlGeneralData;
QPointer<FileSystem> m_fileSystem;
QPointer<SandBoxItemModel> m_fileSystemNew;
public:
Camera* getCamera() { return &camera; }
Light* getLight() {return &lightInfos; }
explicit CustomItemBase(QQuickItem *parent = nullptr) : QQuickFramebufferObject(parent) {
setMirrorVertically(true); //qt default kordinat sistemini opengl'e göre düzenler(bu sayede y: 1.0 ekranın üstü olacak.)
setAcceptedMouseButtons(Qt::AllButtons);
QObject::connect(this, SIGNAL(activeFocusChangedxxNo()), this, SLOT(activeFocusChangedxNo()));
QObject::connect(this, SIGNAL(activeFocusChangedxx(QString)), this, SLOT(activeFocusChangedx(QString)));
QObject::connect(this, SIGNAL(focusChangedSignal(bool)), this, SLOT(focusChangedSlot(bool)));
m_qmlCamera = new Qml_camera(this);
m_qmlLight = new Qml_light(this);
m_qmlGeneralData = new Qml_generalData(this);
m_fileSystem = new FileSystem();
m_fileSystem->setRootPath(m_fileSystem->getCurrentScenePath()+"objects/");
m_fileSystemNew = new SandBoxItemModel();
m_fileSystemNew->setUseMainDirectory(true);
QFile file(m_fileSystem->getMainPath()+"deneme.txt"); //sandbox locations are read from the text file
if (!file.open(QIODevice::ReadOnly)){
qDebug() << "file couldn't open!";
}else{
QString m_fileName = m_fileSystem->getObjectPath();
m_fileSystemNew->setSandBoxDetails(m_fileName);
}
cam()->setMovementSpeed(5.0f);
cam()->setRotationSpeed(0.5f);
cam()->setFov(40.0f);
cam()->setNearDistance(0.01f);
cam()->setFarDistance(100.0f);
light()->setAmbient("#FFFFFFFF");
light()->setDiffuse("#FFFFFFFF");
light()->setSpecular("#FFFFFFFF");
light()->setPointLight(true);
light()->setLinear(0.09f);
light()->setQuadratic(0.032f);
light()->setSpotLight(false);
light()->setCutOff(12.5f);
light()->setOutCutOff(17.5f);
generalData()->setCurrentDepthTest(1);
}
~CustomItemBase();
QQuickFramebufferObject::Renderer *createRenderer() const
{
return new CustomItemRenderer();
}
FileSystem* getFileSystem() const { return m_fileSystem; }
virtual void keyPressEvent(QKeyEvent *event);
virtual void keyReleaseEvent(QKeyEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
QSet<int> getKeysPressed(){return keysPressed;}
bool againUpdate();
void updateCall() {update();};
float deltaTime = 0.0f;
float lastFrame = 0.0f;
float currentFrame = 0.0f;
Q_INVOKABLE void _keyPressEvent();
signals:
void activeFocusChangedxx(const QString &msg);
void activeFocusChangedxxNo();
void focusChangedSignal(bool focus);
public slots:
void activeFocusChangedx(const QString &msg);
void activeFocusChangedxNo(){};
void focusChangedSlot(bool focus);
protected:
Q_INVOKABLE void _mousePressEvent(QPointF p);
public: // synhronize variablen
unsigned int currentDepthTest = 1;
private: // nur variablen
Camera camera;
Light lightInfos;
QSet<int> keysPressed;
//keyboard, mouse io's
float lastMX = 0.0f;
float lastMY = 0.0f;
bool mouseRightClick = false;
bool mouseRightClick2 = false;
};
class OpenGlScreen : public CustomItemBase
{
public:
OpenGlScreen(QQuickItem * parent = nullptr) : CustomItemBase(parent) {}
virtual ~OpenGlScreen() {}
};
#endif // OPENGLITEM_H