-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow.cpp
63 lines (48 loc) · 1.86 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
#include "Window.h"
namespace gps {
void Window::Create(int width, int height, const char *title) {
if (!glfwInit()) {
throw std::runtime_error("Could not start GLFW3!");
}
//window hints
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// for sRGB framebuffer
glfwWindowHint(GLFW_SRGB_CAPABLE, GLFW_TRUE);
// for multisampling/antialising
glfwWindowHint(GLFW_SAMPLES, 4);
this->window = glfwCreateWindow(width, height, title, NULL, NULL);
if (!this->window) {
throw std::runtime_error("Could not create GLFW3 window!");
}
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
// start GLEW extension handler
glewExperimental = GL_TRUE;
glewInit();
// get version info
const GLubyte* renderer = glGetString(GL_RENDERER); // get renderer string
const GLubyte* version = glGetString(GL_VERSION); // version as a string
std::cout << "Renderer: " << renderer << std::endl;
std::cout << "OpenGL version: " << version << std::endl;
//for RETINA display
glfwGetFramebufferSize(window, &this->dimensions.width, &this->dimensions.height);
}
void Window::Delete() {
if (window)
glfwDestroyWindow(window);
//close GL context and any other GLFW resources
glfwTerminate();
}
GLFWwindow* Window::getWindow() {
return this->window;
}
WindowDimensions Window::getWindowDimensions() {
return this->dimensions;
}
void Window::setWindowDimensions(WindowDimensions dimensions) {
this->dimensions = dimensions;
}
}