-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModuleOpenGL.cpp
89 lines (67 loc) · 2.13 KB
/
ModuleOpenGL.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
#include "Application.h"
#include "ModuleOpenGL.h"
#include "ModuleWindow.h"
#include "SDL.h"
#include "glew-2.1.0/include/GL/glew.h"
ModuleOpenGL::ModuleOpenGL()
{
}
// Destructor
ModuleOpenGL::~ModuleOpenGL()
{
}
// Called before render is available
bool ModuleOpenGL::Init()
{
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); // desired version
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 6);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); // we want a double buffer
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); // we want to have a depth buffer with 24 bits
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); // we want to have a stencil buffer with 8 bits
LOG("Creating Renderer context");
context = SDL_GL_CreateContext(App->GetWindow()->window);
GLenum err = glewInit();
// … check for errors
LOG("Using Glew %s", glewGetString(GLEW_VERSION));
LOG("Vendor: %s", glGetString(GL_VENDOR));
LOG("Renderer: %s", glGetString(GL_RENDERER));
LOG("OpenGL version supported %s", glGetString(GL_VERSION));
LOG("GLSL: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
glEnable(GL_DEPTH_TEST); // Enable depth test
glEnable(GL_CULL_FACE); // Enable cull backward faces
glFrontFace(GL_CCW); // Front faces will be counter clockwise
glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
return true;
}
update_status ModuleOpenGL::PreUpdate()
{
SDL_GetWindowSize(App->GetWindow()->window, nullptr, nullptr);
glClearColor(0.0f, 0.2f, 0.2f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
return UPDATE_CONTINUE;
}
// Called every draw update
update_status ModuleOpenGL::Update()
{
return UPDATE_CONTINUE;
}
update_status ModuleOpenGL::PostUpdate()
{
SDL_GL_SwapWindow(App->GetWindow()->window);
return UPDATE_CONTINUE;
}
// Called before quitting
bool ModuleOpenGL::CleanUp()
{
LOG("Destroying renderer");
SDL_GL_DeleteContext(context);
//Destroy window
return true;
}
void ModuleOpenGL::WindowResized(unsigned width, unsigned height)
{
glViewport(0, 0, width, height);
App->GetWindow()->width = width;
App->GetWindow()->height = height;
}