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
|
#include <stdexcept>
#include "Window.hpp"
namespace MC {
Window::Window(const char *title, uint32_t width, uint32_t height) {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_DOUBLEBUFFER, GL_TRUE);
m_window = glfwCreateWindow(width, height, title, nullptr, nullptr);
if (m_window == nullptr) {
throw std::runtime_error("Failed to create window.");
}
glfwMakeContextCurrent(m_window);
glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
}
Window::~Window() {
glfwDestroyWindow(m_window);
}
bool Window::should_close() {
return glfwWindowShouldClose(m_window);
}
GLFWwindow* Window::get() {
return m_window;
}
void Window::close() {
glfwSetWindowShouldClose(m_window, true);
}
bool Window::key(int key, int type) {
return (glfwGetKey(m_window, key) == type);
}
void Window::start_frame() {
glfwSwapBuffers(m_window);
glfwPollEvents();
}
void Window::on_size_change(void (callback)(GLFWwindow*, int, int)) {
glfwSetFramebufferSizeCallback(m_window, static_cast<GLFWframebuffersizefun>(callback));
}
}
|