-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow.cpp
executable file
·96 lines (74 loc) · 1.99 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "Window.h"
namespace Engine
{
Window::Window()
:
window( NULL ),
w( 0 ),
h( 0 )
{}
Window::~Window()
{
cleanup();
}
void errorCallback( int error, const char* desc )
{
fputs( desc, stderr );
fputs( "\n", stderr );
}
int Window::createWindow( int width, int height, const std::string& title, bool fullsreen )
{
glfwInit();
glfwSetErrorCallback( errorCallback );
glfwWindowHint( GLFW_RED_BITS, 8 );
glfwWindowHint( GLFW_GREEN_BITS, 8 );
glfwWindowHint( GLFW_BLUE_BITS, 8 );
glfwWindowHint( GLFW_ALPHA_BITS, 8 );
glfwWindowHint( GLFW_DEPTH_BITS, 24 );
glfwWindowHint( GLFW_STENCIL_BITS, 8 );
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.c_str(), NULL, NULL );
if( !window )
{
fprintf( stderr, "Error: Could not create window\n" );
return -1;
}
glfwGetWindowSize( this->window, &this->w, &this->h );
glfwMakeContextCurrent( this->window );
GLenum err = glewInit();
if( err != GLEW_OK )
{
fprintf( stderr, "Error: could not initialize GLEW, %s\n", glewGetErrorString( err ) );
return -1;
}
setupGL();
return 0;
}
void Window::destroyWindow()
{
glfwDestroyWindow( window );
window = nullptr;
}
int Window::setupGL()
{
glClearColor( 0.0, 0.0, 0.0, 1.0 );
glViewport( 0, 0, w, h );
return 0;
}
void Window::swapBuffers()
{
glfwSwapBuffers( this->window );
}
bool Window::shouldClose()
{
return glfwWindowShouldClose( this->window );
}
void Window::cleanup()
{
if( window )
destroyWindow();
glfwTerminate();
}
}