-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.cpp
66 lines (50 loc) · 1.67 KB
/
window.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
//
// Created by asuka on 09.03.2023.
//
# include "window.hpp"
# include "glfw_system.hpp"
# include <glad/glad.h>
# include <GLFW/glfw3.h>
# include <stdexcept>
namespace snake {
Window::Window(const DisplayData& display_data) {
if (!GLFWSystem::is_initialized()) {
throw std::runtime_error("GLFW must be initialized");
}
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_NATIVE_CONTEXT_API);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
window_ = glfwCreateWindow(display_data.size.x, display_data.size.y,
display_data.title.c_str(), nullptr, nullptr);
if (window_ == nullptr) {
throw std::runtime_error("Failed to create window");
}
glfwMakeContextCurrent(window_);
if (!gladLoadGL()) {
throw std::runtime_error("Failed to load OpenGL");
}
}
Window::~Window() {
if (window_ != nullptr) {
glfwDestroyWindow(window_);
}
}
Window::Window(Window&& other) noexcept {
window_ = other.window_;
other.window_ = nullptr;
}
Window& Window::operator=(Window&& other) noexcept {
window_ = other.window_;
other.window_ = nullptr;
return *this;
}
bool Window::should_close() const {
return glfwWindowShouldClose(window_);
}
void Window::swap_buffers() const {
glfwSwapBuffers(window_);
}
} // snake