-
Notifications
You must be signed in to change notification settings - Fork 2
/
Window.cpp
57 lines (47 loc) · 1.28 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
#include "Window.h"
#include "Errors.h"
#include <GL\glew.h>
namespace NeroEngine{
Window::Window()
{
}
Window::~Window()
{
}
int Window::create(std::string windowName, int screenWidth, int screenHeight, unsigned int currentFlags){
Uint32 flags = SDL_WINDOW_OPENGL;
if (currentFlags & INVISABLE){
flags |= SDL_WINDOW_HIDDEN;
}
if (currentFlags & FULLSCREEN){
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
}
if (currentFlags & BORDERLESS){
flags |= SDL_WINDOW_BORDERLESS;
}
_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!");
}
SDL_GLContext glContext = SDL_GL_CreateContext(_sdlWindow);
if (glContext == nullptr){
fatalError("SDL_GL context could not be created!");
}
GLenum error = glewInit();
if (error != GLEW_OK){
fatalError("Could not initialize glew");
}
//¼ì²éopengl°æ±¾
printf("***OpenGL Version:%s***\n", glGetString(GL_VERSION));
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
//VSYNC
SDL_GL_SetSwapInterval(0);
//open alpha
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
return 0;
}
void Window::swapBuffer(){
SDL_GL_SwapWindow(_sdlWindow);
}
}