-
Notifications
You must be signed in to change notification settings - Fork 1
/
Renderer.cpp
129 lines (98 loc) · 3.52 KB
/
Renderer.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
#include "Renderer.hpp"
// Changed by resizing
int Renderer::w_width = 1366;
int Renderer::w_height = 768;
// Camera
Camera Renderer::camera(glm::vec3(31.1f, -.3f, -9.4f),
glm::vec3(0.0f, 1.0f, 0.0f), -200.f, 10.f);
static const char *getDebugSource(GLenum source) {
switch (source) {
case GL_DEBUG_SOURCE_API:
return "API";
case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
return "WINDOW SYSTEM";
case GL_DEBUG_SOURCE_SHADER_COMPILER:
return "SHADER COMPILER";
case GL_DEBUG_SOURCE_THIRD_PARTY:
return "THIRD PARTY";
case GL_DEBUG_SOURCE_APPLICATION:
return "APPLICATION";
default:
return "UNKNOWN";
}
}
static const char *getDebugType(GLenum type) {
switch (type) {
case GL_DEBUG_TYPE_ERROR:
return "ERROR";
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
return "DEPRECATED BEHAVIOR";
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
return "UDEFINED BEHAVIOR";
case GL_DEBUG_TYPE_PORTABILITY:
return "PORTABILITY";
case GL_DEBUG_TYPE_PERFORMANCE:
return "PERFORMANCE";
case GL_DEBUG_TYPE_OTHER:
return "OTHER";
case GL_DEBUG_TYPE_MARKER:
return "MARKER";
default:
return "UNKNOWN";
}
}
static const char *getDeubgSeverity(GLenum severity) {
switch (severity) {
case GL_DEBUG_SEVERITY_HIGH:
return "HIGH";
case GL_DEBUG_SEVERITY_MEDIUM:
return "MEDIUM";
case GL_DEBUG_SEVERITY_LOW:
return "LOW";
case GL_DEBUG_SEVERITY_NOTIFICATION:
return "NOTIFICATION";
default:
return "UNKNOWN";
}
}
// Callback function for printing debug statements
void GLDebugMessageCallback(GLenum source, GLenum type, GLuint id,
GLenum severity, GLsizei, const GLchar *msg,
const void *) {
const auto _source = getDebugSource(source);
const auto _type = getDebugType(type);
const auto _severity = getDeubgSeverity(severity);
std::cerr << id << ": " << _type << " of " << _severity
<< " severity, raised from " << _source << " : " << msg
<< std::endl;
}
// glfw: whenever mouse position changes this function is executed
void mouse_callback(GLFWwindow *const, double xpos, double ypos) {
static float lastX = xpos, lastY = ypos;
// reversed yoffset since y-coordinates range from bottom to top
Renderer::camera.ProcessMouseMovement(xpos - lastX, lastY - ypos);
lastX = xpos;
lastY = ypos;
}
void processInput(GLFWwindow *const window) {
// NOTE: The static variable initializes only once
static float lastFrame = glfwGetTime(); // Time of last frame
static float deltaTime; // Time between current frame and last frame
const float currentTime = glfwGetTime();
deltaTime = currentTime - lastFrame;
lastFrame = currentTime;
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS)
Renderer::camera.ProcessKeyboard(CameraMovement::FORWARD, deltaTime);
if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS)
Renderer::camera.ProcessKeyboard(CameraMovement::BACKWARD, deltaTime);
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
Renderer::camera.ProcessKeyboard(CameraMovement::LEFT, deltaTime);
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
Renderer::camera.ProcessKeyboard(CameraMovement::RIGHT, deltaTime);
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
Renderer::camera.ProcessKeyboard(CameraMovement::UP, deltaTime);
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
Renderer::camera.ProcessKeyboard(CameraMovement::DOWN, deltaTime);
}