Repository navigation
Expand file tree
/
Copy pathEngine.cpp
More file actions
60 lines (48 loc) · 1.37 KB
/
Copy pathEngine.cpp
File metadata and controls
60 lines (48 loc) · 1.37 KB
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
#include "Engine.hpp"
#include <iostream>
ground::~ground() {
if (window) {
glfwDestroyWindow(window);
}
glfwTerminate();
}
ground::ground(int width, int height, const char* title) :
width(width), height(height), title(title), window(nullptr), Closed(false) {
if (!glfwInit()) {
std::cerr << "Failed to initialize GLFW" << std::endl;
Closed = true;
return;
}
createWindow(width, height, title);
}
void ground::createWindow(int width, int height, const char* title) {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow(width, height, title, nullptr, nullptr);
if (!window) {
std::cerr << "Failed to create GLFW window" << std::endl;
glfwTerminate();
Closed = true;
return;
}
// glfw context
glfwMakeContextCurrent(window);
}
bool ground::isClosed() {
if (Closed) return true;
if (glfwWindowShouldClose(window)) {
Closed = true;
}
return Closed;
}
void ground::setBackgroundColor(const Color& color) {
glClearColor(color.r, color.g, color.b, color.a);
}
void ground::Update() {
if (!window) return;
// clear buffers
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}