-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.cpp
More file actions
53 lines (39 loc) · 1.04 KB
/
Window.cpp
File metadata and controls
53 lines (39 loc) · 1.04 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
#include <iostream>
using namespace std;
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "Window.h"
GLFWwindow* Window::window;
int Window::init(int width, int height, const char* title) {
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
window = glfwCreateWindow(width, height, title, nullptr, nullptr);
if (window == nullptr) {
cout:cerr << "Failed to create GLFW window" << endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
if (glewInit() != GLEW_OK) {
cerr << "Failed to initialize GLEW" << endl;
return -1;
}
glViewport(0, 0, width, height);
return 0;
}
void Window::terminate() {
glfwTerminate();
}
bool Window::should_close() {
return glfwWindowShouldClose(window);
}
void Window::set_should_close(bool flag) {
glfwSetWindowShouldClose(window, flag);
}
void Window::swap_buffers() {
glfwSwapBuffers(window);
}