-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow.cpp
65 lines (51 loc) · 1.5 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
#include "Window.h"
#include <iostream>
Window::Window(int width, int height, const char* title) {
m_Width = width;
m_Height = height;
if (!glfwInit()) {
std::cerr << "Failed to initialize GLFW\n";
return;
}
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_FOCUSED, false);
m_Window = glfwCreateWindow(m_Width, m_Height, title, nullptr, nullptr);
if (!m_Window) {
std::cerr << "Failed to open GLFW window\n";
glfwTerminate();
return;
}
glfwMakeContextCurrent(m_Window);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glViewport(0, 0, m_Width, m_Height);
glfwSetFramebufferSizeCallback(m_Window, framebuffer_size_callback);
}
Window::~Window() {
glfwTerminate();
}
void Window::Clear() const {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void Window::Update() const {
glfwPollEvents();
glfwSwapBuffers(m_Window);
}
bool Window::Closed() const {
return glfwWindowShouldClose(m_Window) == 1;
}
bool Window::ShouldClose() const {
return glfwWindowShouldClose(m_Window);
}
void Window::SwapBuffers() {
glfwSwapBuffers(m_Window);
}
void Window::PollEvents() {
glfwPollEvents();
}
std::pair<int, int> Window::getSize() {
glfwGetFramebufferSize(m_Window, &m_Width, &m_Height);
return { m_Width, m_Height };
}