-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgl_helpers.cpp
47 lines (42 loc) · 1.65 KB
/
gl_helpers.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
#include <lib/gl_helpers.hpp>
namespace GLHelpers {
GLFWwindow * init(const std::string & title, GLuint width, GLuint height) {
if (!glfwInit()) {
std::cerr << "glfwInit failed." << std::endl;
exit(EXIT_FAILURE);
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow * window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr);
if (!window) {
std::cerr << "glfwCreateWindow failed." << std::endl;
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
std::cout << "## OpenGL version: " << glGetString(GL_VERSION) << std::endl;
return window;
}
std::string to_string(const glm::mat4 & m) {
return (boost::format(Helpers::trim_base_indent(R"(
% 10.5f % 10.5f % 10.5f % 10.5f
% 10.5f % 10.5f % 10.5f % 10.5f
% 10.5f % 10.5f % 10.5f % 10.5f
% 10.5f % 10.5f % 10.5f % 10.5f
)"))
% m[0][0] % m[0][1] % m[0][2] % m[0][3]
% m[1][0] % m[1][1] % m[1][2] % m[1][3]
% m[2][0] % m[2][1] % m[2][2] % m[2][3]
% m[3][0] % m[3][1] % m[3][2] % m[3][3]
).str();
}
std::string to_string(const glm::vec3 & v) {
return (boost::format(Helpers::trim_base_indent(R"(
(% 10.5f, % 10.5f, % 10.5f)
)"))
% v.x % v.y % v.z
).str();
}
}