forked from Barnold1953/GraphicsTutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.cpp
More file actions
69 lines (52 loc) · 1.77 KB
/
Window.cpp
File metadata and controls
69 lines (52 loc) · 1.77 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
61
62
63
64
65
66
67
68
69
#include "Window.h"
#include "BengineErrors.h"
namespace Bengine {
Window::Window()
{
}
Window::~Window()
{
}
int Window::create(std::string windowName, int screenWidth, int screenHeight, unsigned int currentFlags) {
Uint32 flags = SDL_WINDOW_OPENGL;
_screenWidth = screenWidth;
_screenHeight = screenHeight;
if (currentFlags & INVISIBLE) {
flags |= SDL_WINDOW_HIDDEN;
}
if (currentFlags & FULLSCREEN) {
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
}
if (currentFlags & BORDERLESS) {
flags |= SDL_WINDOW_BORDERLESS;
}
//Open an SDL window
_sdlWindow = SDL_CreateWindow(windowName.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screenWidth, screenHeight, flags);
if (_sdlWindow == nullptr) {
fatalError("SDL Window could not be created!");
}
//Set up our OpenGL context
SDL_GLContext glContext = SDL_GL_CreateContext(_sdlWindow);
if (glContext == nullptr) {
fatalError("SDL_GL context could not be created!");
}
//Set up glew (optional but recommended)
GLenum error = glewInit();
if (error != GLEW_OK) {
fatalError("Could not initialize glew!");
}
//Check the OpenGL version
std::printf("*** OpenGL Version: %s ***\n", glGetString(GL_VERSION));
//Set the background color to blue
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
//Set VSYNC
SDL_GL_SetSwapInterval(0);
// Enable alpha blend
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
return 0;
}
void Window::swapBuffer() {
SDL_GL_SwapWindow(_sdlWindow);
}
}