-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlearn_model.cpp
490 lines (453 loc) · 22.9 KB
/
learn_model.cpp
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
#include "glad/glad.h"
#include "GLFW/glfw3.h"
#include "Shader.h"
#include "iostream"
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/type_ptr.hpp"
#include "assimp/Importer.hpp"
#include "includes/PosData.h"
#include "includes/Light_Material.h"
#include "Camera.h"
#include "Model.h"
#include "vector"
#include "string"
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void process_input(GLFWwindow* window);
void mouse_callback(GLFWwindow* window, double width_pos, double height_pos);
void scroll_callback(GLFWwindow* window, double unknown_offset, double scroll_offset);
unsigned int load_texture(const std::string& texture_path, unsigned int texture_unit);
static Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
float prev_time = 0.0f;
float delta_time = 0.0f;
float width_mouse = 0.0f;
float height_mouse = 0.0f;
bool first_mouse = true;
bool should_put_light = false;
glm::vec3 light_init_pos = glm::vec3(1.2f, 1.0f, 2.0f);
float overall_light_enhance = 1.0f;
int main() {
generate_glass_info();
// glfw
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
stbi_set_flip_vertically_on_load(true);
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
const GLsizei RENDER_WIDTH = mode->width;
const GLsizei RENDER_HEIGHT = mode->height;
GLFWwindow* window = glfwCreateWindow(RENDER_WIDTH, RENDER_HEIGHT,
"Learn_Model", monitor, nullptr);
if (window == nullptr) {
std::cout << "[FATAL]Fail to create glfw window.." << std::endl;
glfwTerminate();
return -1;
} else {
std::cout << "[INFO]Create glfw window successfully.." << std::endl;
}
glfwMakeContextCurrent(window);
// glad
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
std::cout << "[FATAL]Fail to init GLAD loader.." << std::endl;
glfwTerminate();
return -1;
} else {
std::cout << "[INFO]Init GLAD loader successfully.." << std::endl;
}
glViewport(0, 0, (int)RENDER_WIDTH, (int)RENDER_HEIGHT);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetCursorPosCallback(window, mouse_callback);
glfwSetScrollCallback(window, scroll_callback);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
std::cout << "[INFO]OpenGL version: " << glGetString(GL_VERSION) << std::endl;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// blend policy
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // default
// depth policy(enable depth buffer)
glEnable(GL_DEPTH_TEST);
glm::mat4 proj_mat = glm::mat4(1.0f);
// shader
Shader object_shader("shader/learn_model/model.vert",
"shader/learn_model/model.frag");
Shader light_shader("shader/color_learning/light.vert",
"shader/color_learning/light.frag");
Shader plane_shader("./shader/color_learning/ground.vert",
"./shader/color_learning/ground.frag");
Shader border_shader("./shader/learn_model/border.vert",
"./shader/learn_model/border.frag");
Model our_model("objects/nanosuit/nanosuit.obj");
unsigned int ground_texture_id = load_texture("./textures/awesomeface.png", 3);
unsigned int grass_texture_id = load_texture("./textures/grass.png", 4);
unsigned int glass_texture_id = load_texture("./textures/blending_transparent_window.png", 5);
Light light{};
light.light_color = glm::vec3(1.0f, 1.0f, 1.0f);
light.light_pos = light_init_pos;
float enhance = 0.3;
light.ambient = enhance * glm::vec3(0.4f, 0.4f, 0.4f);
light.diffuse = enhance * glm::vec3(1.8f, 1.8f, 1.8f);
light.specular = enhance * 1.3f * glm::vec3(2.9f, 2.9f, 2.9f);
light.constant = 1.0f;
light.linear = 0.09f;
light.quadratic = 0.032f;
SpotLight spot_light{};
float enhance_spot_light = 0.3;
spot_light.light_color = glm::vec3(1.0f, 1.0f, 1.0f);
spot_light.light_pos = camera.Position;
spot_light.light_dir = camera.Front;
spot_light.ambient = enhance_spot_light * glm::vec3(0.0f, 0.0f, 0.0f);
spot_light.diffuse = enhance_spot_light * glm::vec3(1.8f, 1.8f, 1.8f);
spot_light.specular = enhance_spot_light * 1.3f * glm::vec3(2.9f, 2.9f, 2.9f);
spot_light.cut_off = glm::cos(glm::radians(12.5f));
spot_light.outer_cut_off = glm::cos(glm::radians(17.5f));
spot_light.constant = 1.0f;
spot_light.linear = 0.09f;
spot_light.quadratic = 0.032f;
DirectionalLight directional_light{};
float enhance_directional_light = 0.2;
directional_light.light_color = glm::vec3(1.0f, 1.0f, 1.0f);
directional_light.direction = glm::vec3(-0.2f, -1.0f, -3.0f);
directional_light.ambient = enhance_directional_light * glm::vec3(0.4f, 0.4f, 0.4f);
directional_light.diffuse = enhance_directional_light * glm::vec3(1.8f, 1.8f, 1.8f);
directional_light.specular = enhance_directional_light * 1.3f * glm::vec3(2.9f, 2.9f, 2.9f);
Material ground_material{};
ground_material.diffuse_texture = 3;
ground_material.specular_texture = 3;
ground_material.emission_texture = 3;
ground_material.shininess = 16.0f;
Material grass_material{};
grass_material.diffuse_texture = 4;
grass_material.specular_texture = 4;
grass_material.emission_texture = 4;
grass_material.shininess = 16.0f;
Material glass_material{};
glass_material.diffuse_texture = 5;
glass_material.specular_texture = 5;
glass_material.emission_texture = 5;
glass_material.shininess = 256.0f;
unsigned int ground_VAO, ground_VBO;
{
// ground
glGenVertexArrays(1, &ground_VAO);
glBindVertexArray(ground_VAO);
glGenBuffers(1, &ground_VBO);
glBindBuffer(GL_ARRAY_BUFFER, ground_VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(ground_vertices), ground_vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof (float), (void*) 0); // pos
glEnableVertexAttribArray(0);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 8 * sizeof (float), (void*) (5 * sizeof(float))); // normal
glEnableVertexAttribArray(2);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 8 * sizeof (float), (void*) (3 * sizeof(float))); // tex
glEnableVertexAttribArray(1);
}
unsigned int light_VAO, boxes_VBO;
{
glGenVertexArrays(1, &light_VAO);
glBindVertexArray(light_VAO);
glGenBuffers(1, &boxes_VBO);
glBindBuffer(GL_ARRAY_BUFFER, boxes_VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(wood_box_vertices), wood_box_vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void *) 0); // pos is all we need
glEnableVertexAttribArray(0);
}
{
object_shader.use();
object_shader.set_vec3("light.ambient", light.ambient);
object_shader.set_vec3("light.diffuse", light.diffuse);
object_shader.set_vec3("light.specular", light.specular);
object_shader.set_float("light.constant", light.constant);
object_shader.set_float("light.linear", light.linear);
object_shader.set_float("light.quadratic", light.quadratic);
object_shader.set_vec3("spot_light.ambient", spot_light.ambient);
object_shader.set_vec3("spot_light.diffuse", spot_light.diffuse);
object_shader.set_vec3("spot_light.specular", spot_light.specular);
object_shader.set_float("spot_light.cut_off", spot_light.cut_off);
object_shader.set_float("spot_light.outer_cut_off", spot_light.outer_cut_off);
object_shader.set_float("spot_light.constant", spot_light.constant);
object_shader.set_float("spot_light.linear", spot_light.linear);
object_shader.set_float("spot_light.quadratic", spot_light.quadratic);
object_shader.set_vec3("directional_light.light_color", directional_light.light_color);
object_shader.set_vec3("directional_light.direction", directional_light.direction);
object_shader.set_vec3("directional_light.ambient", directional_light.ambient);
object_shader.set_vec3("directional_light.diffuse", directional_light.diffuse);
object_shader.set_vec3("directional_light.specular", directional_light.specular);
plane_shader.use();
plane_shader.set_vec3("light.ambient", light.ambient);
plane_shader.set_vec3("light.diffuse", light.diffuse);
plane_shader.set_vec3("light.specular", light.specular);
plane_shader.set_float("light.constant", light.constant);
plane_shader.set_float("light.linear", light.linear);
plane_shader.set_float("light.quadratic", light.quadratic);
plane_shader.set_vec3("spot_light.ambient", spot_light.ambient);
plane_shader.set_vec3("spot_light.diffuse", spot_light.diffuse);
plane_shader.set_vec3("spot_light.specular", spot_light.specular);
plane_shader.set_float("spot_light.cut_off", spot_light.cut_off);
plane_shader.set_float("spot_light.outer_cut_off", spot_light.outer_cut_off);
plane_shader.set_float("spot_light.constant", spot_light.constant);
plane_shader.set_float("spot_light.linear", spot_light.linear);
plane_shader.set_float("spot_light.quadratic", spot_light.quadratic);
plane_shader.set_vec3("directional_light.light_color", directional_light.light_color);
plane_shader.set_vec3("directional_light.direction", directional_light.direction);
plane_shader.set_vec3("directional_light.ambient", directional_light.ambient);
plane_shader.set_vec3("directional_light.diffuse", directional_light.diffuse);
plane_shader.set_vec3("directional_light.specular", directional_light.specular);
}
// polygon mode
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// render loop
glBindFramebuffer(GL_FRAMEBUFFER, 0);
while (!glfwWindowShouldClose(window)) {
float current_time = glfwGetTime();
delta_time = current_time - prev_time;
prev_time = current_time;
process_input(window);
// render start
glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
proj_mat = glm::perspective(glm::radians(camera.Zoom),
(float)RENDER_WIDTH / (float) RENDER_HEIGHT,
0.1f, 100.0f);
glEnable(GL_STENCIL_TEST);
// keep the stencil buffer value unchanged if stencil test fail, and set it to ref value if stencil test pass
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
// when drawing the light cube, we will set all the stencil value of fragment of the cube to be 1
glStencilFunc(GL_ALWAYS, 1, 0xFF);
glStencilMask(0xFF); // enable writing to stencil buffer
light_shader.use();
spot_light.light_pos = camera.Position;
spot_light.light_dir = camera.Front;
if (should_put_light){
light.light_pos = camera.Position + 2.0f * camera.Front;
should_put_light = false;
}
{
glm::mat4 view_mat = camera.GetViewMatrix();
{
light_shader.set_mat4("view_mat", view_mat);
light_shader.set_mat4("proj_mat", proj_mat);
light_shader.set_vec3("light_color", light.light_color);
light_shader.set_mat4("model_mat",
glm::scale(glm::translate(glm::mat4(1.0f), light.light_pos),
glm::vec3(0.2f, 0.2f, 0.2f)));
}
glBindVertexArray(light_VAO);
glDrawArrays(GL_TRIANGLES, 0, 36);
}
glStencilFunc(GL_NOTEQUAL, 1, 0xFF); // we wont overwrite the already-drawn light cube
glStencilMask(0x00); // disable writing to stencil buffer
border_shader.use();
{
glm::mat4 view_mat = camera.GetViewMatrix();
{
border_shader.set_mat4("view_mat", view_mat);
border_shader.set_mat4("proj_mat", proj_mat);
border_shader.set_mat4("model_mat",
glm::scale(glm::translate(glm::mat4(1.0f), light.light_pos),
glm::vec3(0.25f, 0.25f, 0.25f)));
}
glBindVertexArray(light_VAO);
glDrawArrays(GL_TRIANGLES, 0, 36);
}
glStencilMask(0xFF); // enable writing to stencil buffer
glDisable(GL_STENCIL_TEST);
// draw model
object_shader.use();
glm::mat4 model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(0.0f, 0.0f, 0.0f)); // translate it down so it's at the center of the scene
model = glm::scale(model, glm::vec3(0.5f, 0.5f, 0.5f));
{
object_shader.set_mat4("model_mat", model);
object_shader.set_mat4("view_mat", camera.GetViewMatrix());
object_shader.set_mat4("proj_mat", proj_mat);
object_shader.set_vec3("light.light_pos", light.light_pos);
object_shader.set_vec3("light.light_color", light.light_color);
object_shader.set_vec3("spot_light.light_color", spot_light.light_color);
object_shader.set_vec3("directional_light.light_color", directional_light.light_color);
object_shader.set_vec3("spot_light.light_pos", spot_light.light_pos);
object_shader.set_vec3("spot_light.light_dir", spot_light.light_dir);
object_shader.set_vec3("view_pos", camera.Position);
object_shader.set_float("overall_light_enhance", overall_light_enhance);
}
our_model.Draw(object_shader);
// draw ground
plane_shader.use();
glBindVertexArray(ground_VAO);
glActiveTexture(GL_TEXTURE0 + ground_material.diffuse_texture);
glBindTexture(GL_TEXTURE_2D, ground_texture_id);
glActiveTexture(GL_TEXTURE0 + ground_material.specular_texture);
glBindTexture(GL_TEXTURE_2D, ground_texture_id);
// glActiveTexture(GL_TEXTURE0 + ground_material.emission_texture);
// glBindTexture(GL_TEXTURE_2D, ground_texture_id);
{
glm::mat4 model_mat = glm::mat4(1.0f);
model_mat = glm::translate(model_mat, glm::vec3(0.0f, -5.0f, 0.0f));
// scale up 25 times
model_mat = glm::scale(model_mat, glm::vec3(25.0f, 25.0f, 25.0f));
{
plane_shader.set_int("material.diffuse_texture", ground_material.diffuse_texture);
plane_shader.set_int("material.specular_texture", ground_material.specular_texture);
// plane_shader.set_int("material.emission_texture", ground_material.emission_texture);
plane_shader.set_float("material.shininess", ground_material.shininess);
plane_shader.set_mat4("view_mat", camera.GetViewMatrix());
plane_shader.set_mat4("proj_mat", proj_mat);
plane_shader.set_vec3("light.light_pos", light.light_pos);
plane_shader.set_vec3("light.light_color", light.light_color);
plane_shader.set_vec3("view_pos", camera.Position);
plane_shader.set_mat4("model_mat", model_mat);
plane_shader.set_vec3("spot_light.light_pos", spot_light.light_pos);
plane_shader.set_vec3("spot_light.light_dir", spot_light.light_dir);
plane_shader.set_vec3("spot_light.light_color", spot_light.light_color);
plane_shader.set_vec3("directional_light.light_color", directional_light.light_color);
plane_shader.set_vec3("light.light_color", light.light_color);
}
glDrawArrays(GL_TRIANGLES, 0, 6);
}
// draw vegetation, use the same VAO as ground, since it's also a plane
glActiveTexture(GL_TEXTURE0 + grass_material.diffuse_texture);
glBindTexture(GL_TEXTURE_2D, grass_texture_id);
glActiveTexture(GL_TEXTURE0 + grass_material.specular_texture);
glBindTexture(GL_TEXTURE_2D, grass_texture_id);
{
plane_shader.set_vec3("light.light_pos", light.light_pos);
plane_shader.set_vec3("light.light_color", light.light_color);
plane_shader.set_vec3("view_pos", camera.Position);
plane_shader.set_vec3("spot_light.light_pos", spot_light.light_pos);
plane_shader.set_vec3("spot_light.light_dir", spot_light.light_dir);
plane_shader.set_vec3("spot_light.light_color", spot_light.light_color);
plane_shader.set_vec3("directional_light.light_color", directional_light.light_color);
plane_shader.set_vec3("light.light_color", light.light_color);
}
// no more emission texture needed, loop over vegetation_pos
{
plane_shader.set_int("material.diffuse_texture", grass_material.diffuse_texture);
plane_shader.set_int("material.specular_texture", grass_material.specular_texture);
plane_shader.set_float("material.shininess", grass_material.shininess);
plane_shader.set_mat4("view_mat", camera.GetViewMatrix());
plane_shader.set_mat4("proj_mat", proj_mat);
}
for (auto vegetation_po : vegetation_pos) {
glm::mat4 model_mat = glm::mat4(1.0f);
model_mat = glm::translate(model_mat, vegetation_po);
// rotate the vegetation 90 degrees around the x-axis so it stands up
model_mat = glm::rotate(model_mat, glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0));
{
plane_shader.set_mat4("model_mat", model_mat);
}
glDrawArrays(GL_TRIANGLES, 0, 6);
}
// draw glass
glActiveTexture(GL_TEXTURE0 + glass_material.diffuse_texture);
glBindTexture(GL_TEXTURE_2D, glass_texture_id);
glActiveTexture(GL_TEXTURE0 + glass_material.specular_texture);
glBindTexture(GL_TEXTURE_2D, glass_texture_id);
// no more emission texture needed, spawn 100 glass plane randomly
// sort the glass plane by distance to camera
std::map<float, int > sorted;
for (int i = 0; i < GLASS_NUM; ++i) {
float distance = glm::length(camera.Position - glass_pos[i]);
sorted[distance] = i;
}
{
plane_shader.set_int("material.diffuse_texture", glass_material.diffuse_texture);
plane_shader.set_int("material.specular_texture", glass_material.specular_texture);
plane_shader.set_float("material.shininess", glass_material.shininess);
plane_shader.set_mat4("view_mat", camera.GetViewMatrix());
plane_shader.set_mat4("proj_mat", proj_mat);
}
for (auto it = sorted.rbegin(); it != sorted.rend(); ++it) {
glm::mat4 model_mat = glm::mat4(1.0f);
model_mat = glm::translate(model_mat, glass_pos[it->second]);
// scale
model_mat = glm::scale(model_mat, glass_scale[it->second]);
// rotate
model_mat = glm::rotate(model_mat, glm::radians(glass_rotate[it->second].x),
glm::vec3(1.0f, 0.0f, 0.0f));
model_mat = glm::rotate(model_mat, glm::radians(glass_rotate[it->second].y),
glm::vec3(0.0f, 1.0f, 0.0f));
model_mat = glm::rotate(model_mat, glm::radians(glass_rotate[it->second].z),
glm::vec3(0.0f, 0.0f, 1.0f));
{
plane_shader.set_mat4("model_mat", model_mat);
}
glDrawArrays(GL_TRIANGLES, 0, 6);
}
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
glViewport(0, 0, width, height);
}
void mouse_callback(GLFWwindow* window, double width_pos, double height_pos) {
if (first_mouse) {
width_mouse = (float)width_pos;
height_mouse = (float)height_pos;
first_mouse = false;
}
float width_offset = (float)width_pos - width_mouse;
float height_offset = height_mouse - (float)height_pos;
width_mouse = (float)width_pos;
height_mouse = (float)height_pos;
camera.ProcessMouseMovement(width_offset, height_offset);
}
void scroll_callback(GLFWwindow* window, double unknown_offset, double scroll_offset) {
camera.ProcessMouseScroll((float)scroll_offset);
}
unsigned int load_texture(const std::string& texture_path, unsigned int texture_unit) {
int texture_width, texture_height, texture_channels;
unsigned char* data = stbi_load(texture_path.c_str(), &texture_width,
&texture_height, &texture_channels, 0);
if (data == nullptr) {
std::cout << "[FATAL]Fail to load texture" << std::endl;
stbi_image_free(data);
return -1;
} else {
std::cout << "[INFO]Load texture successfully, channels=" << texture_channels << std::endl;
unsigned int texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
GLenum format;
if (texture_channels == 1)
format = GL_RED;
else if (texture_channels == 3)
format = GL_RGB;
else if (texture_channels == 4)
format = GL_RGBA;
// repeat policy
glTextureParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTextureParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// interpolation policy
glTextureParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
// WARN: We should not set the Mag_Filter to be a mip-map filter, because for mag, we will never use mipmap
glTextureParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, format, texture_width, texture_height, 0, format, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
stbi_image_free(data);
return texture;
}
}
void process_input(GLFWwindow* window) {
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
camera.ProcessKeyboard(FORWARD, delta_time);
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
camera.ProcessKeyboard(BACKWARD, delta_time);
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
camera.ProcessKeyboard(LEFT, delta_time);
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
camera.ProcessKeyboard(RIGHT, delta_time);
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
should_put_light = true;
// q, e: light enhance
if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)
overall_light_enhance += delta_time;
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)
overall_light_enhance -= delta_time;
// r to regenerate glass
if (glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS)
generate_glass_info();
}