-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow.hpp
79 lines (59 loc) · 1.54 KB
/
Window.hpp
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
#pragma once
#include "GLFW/glfw3.h"
#include "GLAD/glad.h"
#include "Keyboard.hpp"
#include "Mouse.hpp"
#include <cstdlib>
#include <cstdio>
#include <utility>
struct Window
{
static void ErrorCallback(int error, const char* description)
{
fprintf(stderr, "Error: %s\n", description);
}
GLFWwindow* window = nullptr;
Window()
{
glfwSetErrorCallback(ErrorCallback);
if (!glfwInit())
{
exit(EXIT_FAILURE);
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow(1280, 720, "TheCube", NULL, NULL);
if (!window)
{
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
gladLoadGL();
glfwSwapInterval(1);
glEnable(GL_DEPTH_TEST);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
glfwSetKeyCallback(window, Keyboard::KeyCallback);
glfwSetCursorPosCallback(window, Mouse::MouseCallback);
}
bool ShouldClose()
{
return glfwWindowShouldClose(window);
}
std::pair<int, int> GetSize()
{
int width, height;
glfwGetFramebufferSize(window, &width, &height);
return { width, height };
}
void SwapBuffer()
{
glfwSwapBuffers(window);
}
~Window()
{
glfwDestroyWindow(window);
glfwTerminate();
}
};