-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathopengl.cpp
More file actions
79 lines (70 loc) · 1.87 KB
/
opengl.cpp
File metadata and controls
79 lines (70 loc) · 1.87 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
70
71
72
73
74
75
76
77
78
79
#include "opengl.hpp"
#include "manager.hpp"
#define NOMUSIC
#ifdef WIN32
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <windows.h>
#else
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
#endif
#include <GL/glew.h>
Opengl::Opengl()
{
fprintf(stderr, "Making friends with OpenGL...\n");
// Default failsafe settings
screenX = 800;
screenY = 600;
screenBPP = 32;
fps = 60;
limit_fps = true;
fullscreen = false;
}
Opengl::~Opengl()
{
fprintf(stderr, "Bidding farewells with the graphics libraries...\n");
TTF_Quit();
SDL_Quit();
}
bool Opengl::start()
{
fprintf(stderr, "Initializing: SDL\n");
SDL_Init(SDL_INIT_EVERYTHING);
SDL_WM_SetCaption("Generic Demo Template", NULL);
fprintf(stderr, "Initializing: SDL_ttf\n");
TTF_Init();
fprintf(stderr, "Initializing: Video mode\n");
if (fullscreen)
SDL_SetVideoMode(screenX, screenY, screenBPP, SDL_OPENGL |SDL_FULLSCREEN);
else
SDL_SetVideoMode(screenX, screenY, screenBPP, SDL_OPENGL |SDL_RESIZABLE);
fprintf(stderr, "Initializing: OpenGL Glew\n");
GLenum err = glewInit();
if (GLEW_OK != err)
{
fprintf(stderr, "Error starting Glew: %s \n", glewGetErrorString(err));
manager.getEnter();
manager.stop();
return false;
}
fprintf(stderr, "Using Glew version %s \n", glewGetString(GLEW_VERSION));
fprintf(stderr, "OpenGL init finished\n");
return true;
}
float Opengl::giveTicks()
{
return SDL_GetTicks();
}
void Opengl::swapBuffers()
{
SDL_GL_SwapBuffers();
}
void Opengl::setFullscreen(bool fs) { fullscreen = fs; }
void Opengl::setScreenX(int x) { screenX = x; }
void Opengl::setScreenY(int y) { screenY = y; }
void Opengl::setBPP(int b) { screenBPP = b; }
void Opengl::setFPS(int f) { fps = f; }
void Opengl::setLimitFPS(bool b) { limit_fps = b; }