-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.cpp
95 lines (78 loc) · 2 KB
/
display.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
#include"display.h"
static void initialize_and_configure_glfw();
static void initialize_glad();
static void frame_buffer_size_callback(GLFWwindow* window, int width, int height);
static void mouse_callback(GLFWwindow* window, double xpos, double ypos);
static void scroll_callback(GLFWwindow* window, double x_offset, double y_offset);
Display::Display(const unsigned short WIDTH, const unsigned short HEIGHT, const char* TITLE)
{
initialize_and_configure_glfw();
window = glfwCreateWindow(
WIDTH,
HEIGHT,
TITLE,
NULL,
NULL
);
if(window == NULL)
{
std::cout << "Failed to create window" << std::endl;
glfwTerminate();
exit(-1);
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, frame_buffer_size_callback);
glfwSetCursorPosCallback(window, mouse_callback);
glfwSetScrollCallback(window, scroll_callback);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
initialize_glad();
}
Display::~Display()
{
}
GLFWwindow* Display::get_window() const
{
return window;
}
void Display::swap_buffers()
{
glfwSwapBuffers(window);
}
void Display::poll_event()
{
glfwPollEvents();
}
bool Display::is_open()
{
return !glfwWindowShouldClose(window);
}
static void initialize_and_configure_glfw()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __MACOS__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
}
static void initialize_glad()
{
if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
exit(-1);
}
}
static void frame_buffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
static void mouse_callback(GLFWwindow* window, double xpos, double ypos)
{
input::mouse(window, xpos, ypos);
}
static void scroll_callback(GLFWwindow* window, double x_offset, double y_offset)
{
input::scroll(window, x_offset, y_offset);
}