-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
571 lines (433 loc) · 17.8 KB
/
main.cpp
File metadata and controls
571 lines (433 loc) · 17.8 KB
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
#include<iostream>
#include<cassert>
#include<array>
#include<fstream>
#include<vector>
#include<GL/glew.h>
#include<GLFW/glfw3.h>
#include<glm/glm.hpp>
#include<glm/ext.hpp>
#include<glm/gtx/string_cast.hpp>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
int width = 800;
int height = 600;
std::string ReadFile(const char* FilePath) {
std::string FileContents;
if (std::ifstream FileStream{ FilePath, std::ios::in }) {
FileContents.assign((std::istreambuf_iterator<char>(FileStream)), std::istreambuf_iterator<char>());
}
return FileContents;
}
void CheckShader(GLuint ShaderID) {
//ShaderID tem que ser um identificador de um shader já compilado
GLint Result = GL_TRUE;
glGetShaderiv(ShaderID, GL_COMPILE_STATUS, &Result);
if (Result == GL_FALSE) {
//obtém o tamanho do log
GLint InfoLogLenght = 0;
glGetShaderiv(ShaderID, GL_INFO_LOG_LENGTH, &InfoLogLenght);
std::string ShaderInfoLog(InfoLogLenght, '\0');
glGetShaderInfoLog(ShaderID, InfoLogLenght, nullptr, &ShaderInfoLog[0]);
if (InfoLogLenght > 0) {
std::cout << "Erro no shader" << std::endl;
std::cout << ShaderInfoLog << std::endl;
assert(false);
}
}
}
GLuint LoadShaders(const char* VertexShaderFile, const char* FragmentShaderFile) {
//cria os identificadores
GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
std::string VertexShaderSource = ReadFile(VertexShaderFile);
std::string FragmentShaderSource = ReadFile(FragmentShaderFile);
assert(!VertexShaderSource.empty());
assert(!FragmentShaderSource.empty());
std::cout << "Compilando " << VertexShaderFile << std::endl;
const char* VertexShaderSourcePtr = VertexShaderSource.c_str();
glShaderSource(VertexShaderID, 1, &VertexShaderSourcePtr, nullptr);
glCompileShader(VertexShaderID);
CheckShader(VertexShaderID);
std::cout << "Compilando " << FragmentShaderFile << std::endl;
const char* FragmentShaderSourcePtr = FragmentShaderSource.c_str();
glShaderSource(FragmentShaderID, 1, &FragmentShaderSourcePtr, nullptr);
glCompileShader(FragmentShaderID);
CheckShader(FragmentShaderID);
std::cout << "Linkando o programa" << std::endl;
GLuint ProgramID = glCreateProgram();
glAttachShader(ProgramID, VertexShaderID);
glAttachShader(ProgramID, FragmentShaderID);
glLinkProgram(ProgramID);
//verifica a linkagem
GLint Result = GL_TRUE;
glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
if (Result == GL_FALSE) {
//pega o log para saber qual é o problema
GLint InfoLogLenght = 0;
glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLenght);
if (InfoLogLenght > 0) {
std::string ProgramInfoLog(InfoLogLenght, '\0');
glGetProgramInfoLog(ProgramID, InfoLogLenght, nullptr, &ProgramInfoLog[0]);
std::cout << "Erro ao linkar o programa" << std::endl;
std::cout << ProgramInfoLog << std::endl;
assert(false);
}
}
glDetachShader(ProgramID, VertexShaderID);
glDetachShader(ProgramID, FragmentShaderID);
glDeleteShader(VertexShaderID);
glDeleteShader(FragmentShaderID);
return ProgramID;
}
GLuint LoadTexture(const char* TextureFile) {
std::cout << "Carregando Textura" << TextureFile << std::endl;
stbi_set_flip_vertically_on_load(true);
int TextureWidth = 0, TextureHeight = 0, NumberOfComponents = 0;
unsigned char* TextureData = stbi_load(TextureFile, &TextureWidth, &TextureHeight, &NumberOfComponents, 3);
assert(TextureData);
//gera o identificador de textura
GLuint TextureID;
glGenTextures(1, &TextureID);
//habilita a textura para ser modifcada
glBindTexture(GL_TEXTURE_2D, TextureID);
//copia a textura para a memória de vídeo (GPU)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TextureWidth, TextureHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureData);
//filtros de magnificação e minificação
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
// configuração do texture wrapping
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//gera o mipmap a partir da textura
glGenerateMipmap(GL_TEXTURE_2D);
//desliga a textura pois la já foi copiada para a gpu
glBindTexture(GL_TEXTURE_2D, 0);
stbi_image_free(TextureData);
return TextureID;
}
struct Vertex {
glm::vec3 Position;
glm::vec3 Normal;
glm::vec3 Color;
glm::vec2 UV; //cordenada de textura do vértice
};
struct DirectionalLight {
glm::vec3 Direction;
GLfloat Intensity;
};
GLuint LoadGeometry() {
//quadrado em coordenadas normalizadas
std::array<Vertex, 6 > quad = {
Vertex{glm::vec3{-1.0f, -1.0f, 0.0f}, glm::vec3{0.0f, 0.0f, 1.0f}, glm::vec3{1.0f,0.0f,0.0f}, glm::vec2{0.0f, 0.0f}}, //vértice canto inferior esquerdo
Vertex{glm::vec3{1.0f, -1.0f, 0.0f}, glm::vec3{0.0f,0.0f,1.0f}, glm::vec3{0.0f,1.0f,0.0f}, glm::vec2{1.0f, 0.0f}}, //vértice canto inferior direito
Vertex{glm::vec3{1.0f, 1.0f, 0.0f},glm::vec3{0.0f, 0.0f, 1.0f}, glm::vec3{1.0f,0.0f,0.0f}, glm::vec2{1.0f, 1.0f}},
Vertex{glm::vec3{-1.0f, 1.0f, 0.0f},glm::vec3{0.0f, 0.0f, 1.0f}, glm::vec3{0.0f,0.0f,1.0f}, glm::vec2{0.0f, 1.0f}}
};
//Define a lista de elementos que formam os triângulos
std::array<glm::ivec3, 2> Indices = {
glm::ivec3{0, 1, 3},
glm::ivec3{3, 1, 2}
};
//copia os dados para a GPU
GLuint VertexBuffer;
//gera o identifcador do vertexbuffer - VBO
glGenBuffers(1, &VertexBuffer);
//pede para o opengl gerar o identificador do EBO
GLuint ElementBuffer = 0;
glGenBuffers(1, &ElementBuffer);
//ativa o vertex como sendo o buffer para onde os dados vão ser copiados
glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer);
//copias os dados para a memória de vídeo
glBufferData(GL_ARRAY_BUFFER, sizeof(quad), quad.data(), GL_STATIC_DRAW);
//copia os dados do Element Buffer para a GPU
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices), Indices.data(), GL_STATIC_DRAW);
//Gera o vertex array object - VAO
GLuint VAO;
glGenVertexArrays(1, &VAO);
//habilita o VAO
glBindVertexArray(VAO);
//Atributo para cor nos vértices
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
//aponta para o OpenGl quaul vai ser o buffer ativo no momento
glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer);
//informa onde dentro do buffer estão os vértices
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_TRUE, sizeof(Vertex), reinterpret_cast<void*>(offsetof(Vertex, Normal)));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_TRUE, sizeof(Vertex), reinterpret_cast<void*>(offsetof(Vertex, Color)));
glVertexAttribPointer(3, 2, GL_FLOAT, GL_TRUE, sizeof(Vertex), reinterpret_cast<void*>(offsetof(Vertex, UV)));
glBindVertexArray(0);
return VAO;
}
void GenerateSphereMesh(GLuint Resolution, std::vector<Vertex>& Vertices, std::vector<glm::ivec3>&Indices) {
Vertices.clear();
Indices.clear();
constexpr float Pi = glm::pi<float>();
constexpr float TwoPi = glm::two_pi<float>();
float InvResolution = 1.0f / static_cast<float>(Resolution - 1);
for (GLuint UIndex = 0; UIndex < Resolution; ++UIndex) {
const float U = UIndex * InvResolution;
const float Theta = glm::mix(0.0f, Pi, U);
for (GLuint VIndex = 0; VIndex < Resolution; ++VIndex) {
const float V = VIndex * InvResolution;
const float Phi = glm::mix(0.0f, TwoPi, V);
glm::vec3 VertexPosition = {
glm::sin(Theta) * glm::cos(Phi),
glm::sin(Theta)* glm::sin(Phi),
glm::cos(Theta)
};
Vertex Vertex{
VertexPosition,
glm::normalize(VertexPosition),
glm::vec3{1.0f, 1.0f, 1.0f},
glm::vec2{1.0f - U, V}
};
Vertices.push_back(Vertex);
}
}
for (GLuint U = 0; U < Resolution - 1; ++U) {
for (GLuint V = 0; V < Resolution - 1; ++V) {
GLuint P0 = U + V * Resolution;
GLuint P1 = (U + 1) + V * Resolution;
GLuint P2 = (U + 1) + (V + 1) * Resolution;
GLuint P3 = U + (V + 1) * Resolution;
Indices.push_back(glm::ivec3{ P0, P1, P3 });
Indices.push_back(glm::ivec3{ P3, P1, P2 });
}
}
}
GLuint LoadSphere(GLuint& NumVertices, GLuint& NumIndices) {
std::vector<Vertex> Vertices;
std::vector<glm::ivec3> Triangles;
GenerateSphereMesh(50, Vertices, Triangles);
NumVertices = Vertices.size();
NumIndices = Triangles.size() * 3;
GLuint VertexBuffer;
glGenBuffers(1, &VertexBuffer);
//ativa o vertex como sendo o buffer para onde os dados vão ser copiados
glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer);
//copias os dados para a memória de vídeo
glBufferData(GL_ARRAY_BUFFER, Vertices.size() * sizeof(Vertex), Vertices.data(), GL_STATIC_DRAW);
GLuint ElementBuffer;
glGenBuffers(1, &ElementBuffer);
//ativa o vertex como sendo o buffer para onde os dados vão ser copiados
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer);
//copias os dados para a memória de vídeo
glBufferData(GL_ELEMENT_ARRAY_BUFFER, NumIndices * sizeof(GLuint), Triangles.data(), GL_STATIC_DRAW);
GLuint VAO;
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
//Atributo para cor nos vértices
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
//aponta para o OpenGl quaul vai ser o buffer ativo no momento
glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer);
//informa onde dentro do buffer estão os vértices
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_TRUE, sizeof(Vertex), reinterpret_cast<void*>(offsetof(Vertex, Normal)));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_TRUE, sizeof(Vertex), reinterpret_cast<void*>(offsetof(Vertex, Color)));
glVertexAttribPointer(3, 2, GL_FLOAT, GL_TRUE, sizeof(Vertex), reinterpret_cast<void*>(offsetof(Vertex, UV)));
glBindVertexArray(0);
return VAO;
}
class FlyCamera {
public:
void MoveForward(float Amount) {
LocationVRP += glm::normalize(Direction) * Amount * Speed;
}
void MoveRight(float Amount) {
glm::vec3 Right = glm::normalize(glm::cross(Direction, ViewUp));
LocationVRP += Right * Amount * Speed;
}
void Look(float Yaw, float Pitch) {
Yaw *= Sensitivity;
Pitch *= Sensitivity;
const glm::vec3 Right = glm::normalize(glm::cross(Direction, ViewUp));
const glm::mat4 I = glm::identity < glm::mat4>();
glm::mat4 YawRotation = glm::rotate(I, glm::radians(Yaw), ViewUp);
glm::mat4 PitchRotation = glm::rotate(I, glm::radians(Pitch), Right);
ViewUp = PitchRotation * glm::vec4{ ViewUp, 0.0f };
Direction = YawRotation * PitchRotation * glm::vec4{ Direction, 0.0f };
}
glm::mat4 GetView() const {
return glm::lookAt(LocationVRP, LocationVRP + Direction, ViewUp);
}
glm::mat4 GetViewProjection() const {
//glm::mat4 View = glm::lookAt(LocationVRP, LocationVRP + Direction, ViewUp);
glm::mat4 Projection = glm::perspective(angulo_de_visao, razao_aspecto, near, far);
return Projection * GetView();
}
//Parametros de Interatividade
float Speed = 5.0f;
float Sensitivity = 0.1f;
//Definição da Matriz de View
glm::vec3 LocationVRP{ 0.0f, 0.0f, 10.0f };
glm::vec3 Direction{0.0f, 0.0f, -1.0f};
glm::vec3 ViewUp{ 0.0f, 1.0f, 0.0f };
//Definição da Matriz de projeção
float angulo_de_visao = glm::radians(45.0f);
float razao_aspecto = width / height;
float near = 0.01f;
float far = 1000.0f;
};
FlyCamera Camera;
bool bEnableMouseMovement = false;
glm::vec2 PreviousCursor{ 0.0, 0.0 };
void MouseButtonCallback(GLFWwindow* Window, int Button, int Action, int Modifiers) {
//std::cout << "Button: " << Button << " Action: " << Action << " Modifiers: " << Modifiers << std::endl;
if (Button == GLFW_MOUSE_BUTTON_LEFT) {
if (Action == GLFW_PRESS) {
glfwSetInputMode(Window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
double X, Y;
glfwGetCursorPos(Window, &X, &Y);
PreviousCursor = glm::vec2{ X,Y };
bEnableMouseMovement = true;
}
else if (Action == GLFW_RELEASE) {
glfwSetInputMode(Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
bEnableMouseMovement = false;
}
}
}
void MouseMotionCallBack(GLFWwindow* Window, double X, double Y) {
if (bEnableMouseMovement) {
glm::vec2 CurrentCursor{ X, Y };
glm::vec2 DeltaCursor = CurrentCursor - PreviousCursor ;
//std::cout << glm::to_string(DeltaCursor) << std::endl;
Camera.Look(-DeltaCursor.x, -DeltaCursor.y);
PreviousCursor = CurrentCursor;
}
}
void Resize(GLFWwindow* Window, int NewWidth, int NewHeight) {
width = NewWidth;
height = NewHeight;
Camera.razao_aspecto = static_cast<float>(width) / height;
glViewport(0, 0, width, height);
}
int main() {
//inicialização
if (!glfwInit()) {
std::cerr << "Failed to initialize GLFW" << std::endl;
return -1;
}
//criar a janela
GLFWwindow* Window = glfwCreateWindow(width, height, "Blue Marble", nullptr, nullptr);
if (!Window){
std::cout << "Erro ao criar janela" << std::endl;
glfwTerminate();
return 1;
}
//Cadastra as callbacks no GLFW
glfwSetMouseButtonCallback(Window, MouseButtonCallback);
glfwSetCursorPosCallback(Window, MouseMotionCallBack);
glfwSetFramebufferSizeCallback(Window, Resize);
//ativa o contexto criado na janela window
glfwMakeContextCurrent(Window);
//habilita e desabilita o v-sync
glfwSwapInterval(1);
if (glewInit() != GLEW_OK) {
std::cerr << "Failed to initialize GLEW" << std::endl;
return -1;
}
//Obtem informações do driver
std::cout << "OpenGL Version: " << glGetString(GL_VERSION) << std::endl;
Resize(Window, width, height);
// Compilar o vertex e o fragment shader
GLuint ProgramID = LoadShaders("shaders/triangle_vert.glsl", "shaders/triangle_frag.glsl");
GLuint TextureID = LoadTexture("textures/earth_2k.jpg");
GLuint CloudTextureID = LoadTexture("textures/earth_clouds_2k.jpg");
GLuint QuadVAO = LoadGeometry();
GLuint SphereNumVertices = 0;
GLuint SphereNumIndices = 0;
GLuint SphereVAO = LoadSphere(SphereNumVertices, SphereNumIndices);
std::cout << "Numero de vertices da esfera: " << SphereNumVertices << std::endl;
std::cout << "Numero de indices da esfera: " << SphereNumIndices << std::endl;
//Model Matrix
glm::mat4 I = glm::identity<glm::mat4>();
glm::mat4 ModelMatrix = glm::rotate(I, glm::radians(90.0f), glm::vec3{ 1,0,0 });
//definição da cor de fundo em RGBA
glClearColor(0.0f, 0.0f, 0.0f, 1.0);
//salva o tempo do frame anterior
double PreviousTime = glfwGetTime();
//habilita o backface culling
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
//habilita o teste de porfundidade (Z-Buffer)
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
//criação da fonte de luz direcional
DirectionalLight Light;
Light.Direction = glm::vec3{ 0.0f, 0.0f, -1.0f };
Light.Intensity = 1.0f;
while(!glfwWindowShouldClose(Window)){
double CurrentTime = glfwGetTime();
double DeltaTime = CurrentTime - PreviousTime;
if (DeltaTime > 0.0) {
PreviousTime = CurrentTime;
}
//limpa o buffer de cor e preenche com a for configurada
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Ativar o programa de shader
glUseProgram(ProgramID);
glm::mat4 NormalMatrix = glm::inverse(glm::transpose(Camera.GetView() * ModelMatrix));
glm::mat4 ViewProjectionMatrix = Camera.GetViewProjection();
glm::mat4 ModelViewProjection = ViewProjectionMatrix * ModelMatrix;
GLint TimeLoc = glGetUniformLocation(ProgramID, "Time");
glUniform1f(TimeLoc, CurrentTime);
GLint ModelViewProjectionLoc = glGetUniformLocation(ProgramID, "ModelViewProjection");
glUniformMatrix4fv(ModelViewProjectionLoc, 1, GL_FALSE, glm::value_ptr(ModelViewProjection));
GLint NormalMatrixLoc = glGetUniformLocation(ProgramID, "NormalMatrix");
glUniformMatrix4fv(NormalMatrixLoc, 1, GL_FALSE, glm::value_ptr(NormalMatrix));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, TextureID);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, CloudTextureID);
GLint TextureSamplerLoc = glGetUniformLocation(ProgramID, "TextureSampler");
glUniform1i(TextureSamplerLoc, 0);
GLint CloudTextureLoc = glGetUniformLocation(ProgramID, "CloudsTexture");
glUniform1i(CloudTextureLoc, 1);
GLint LightDirectionLoc = glGetUniformLocation(ProgramID, "LightDirection");
glUniform3fv(LightDirectionLoc, 1, glm::value_ptr(Camera.GetView()* glm::vec4{ Light.Direction, 0.0f }));
GLint LightIntensityLoc = glGetUniformLocation(ProgramID, "LihgtIntensity");
glUniform1f(LightIntensityLoc, Light.Intensity);
glBindVertexArray(SphereVAO);
//desenha o objeto com os dados armazenados no vertexbuffer
glPointSize(10.0f);
glLineWidth(10.0f);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glDrawElements(GL_TRIANGLES, SphereNumIndices, GL_UNSIGNED_INT, nullptr);
glBindVertexArray(0);
//Desabilita o programa ativo
glUseProgram(0);
//Processamento de todos os eventos da fila
glfwPollEvents();
//Envia o conteúdo para ser desenhado
glfwSwapBuffers(Window);
//Processamento dos inputs do teclado
if (glfwGetKey(Window, GLFW_KEY_W) == GLFW_PRESS) {
Camera.MoveForward(1.0f * DeltaTime);
}
if (glfwGetKey(Window, GLFW_KEY_S) == GLFW_PRESS) {
Camera.MoveForward(-1.0f * DeltaTime);
}
if (glfwGetKey(Window, GLFW_KEY_A) == GLFW_PRESS) {
Camera.MoveRight(-1.0f * DeltaTime);
}
if (glfwGetKey(Window, GLFW_KEY_D) == GLFW_PRESS) {
Camera.MoveRight(1.0f * DeltaTime);
}
}
//desaloca o buffer
glDeleteVertexArrays(1, &QuadVAO);
//encerra o glfw
glfwTerminate();
return 0;
}