5bool App::initialized =
false;
11 glewExperimental=GL_TRUE;
20 unsigned int flags = IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_TIF;
21 if((IMG_Init(flags) & flags) != flags) {
34 if(SDL_Init(SDL_INIT_VIDEO |
37 SDL_INIT_GAMECONTROLLER)) {
73 App::initialized =
true;
75 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
76 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
77 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
78 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
94 if(minor < 0 || minor > 3) {
95 App::error_string.push_back(
"Unsupported version number. Defaulting to version 3.0");
100 }
else if(major == 4) {
101 if(minor < 0 || minor > 6) {
102 App::error_string.push_back(
"Unsupported version number. Defaulting to version 3.0");
108 App::error_string.push_back(
"Unsupported version number. Defaulting to version 3.0");
111 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, maj);
112 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, min);
118 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, depth_size);
119 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, stencil_size);
123 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
124 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, number_samples);
128 App::initialized =
false;
139 SDL_EnableScreenSaver();
141 SDL_DisableScreenSaver();
147 ret = SDL_GL_SetSwapInterval(-1);
149 ret = SDL_GL_SetSwapInterval(1);
153 ret = SDL_GL_SetSwapInterval(0);
159 std::string path(argv[0]);
160 size_t pos = path.find_last_of(
"\\/");
161 if(pos == std::string::npos) {
167 ret = chdir(path.c_str());
169 ret = _chdir(path.c_str());
172 std::string error(
"An error occured while trying to change "
173 "current working directory to the directory containing "
174 "the executable file.");
182 std::string err_string;
183 GLenum err = GL_NO_ERROR;
188 case GL_INVALID_ENUM:
189 err_string =
"INVALID_ENUM";
191 case GL_INVALID_VALUE:
192 err_string =
"INVALID_VALUE";
194 case GL_INVALID_OPERATION:
195 err_string =
"INVALID_OPERATION";
197 case GL_INVALID_FRAMEBUFFER_OPERATION:
198 err_string =
"INVALID_FRAMEBUFFER_OPERATION";
200 case GL_OUT_OF_MEMORY:
201 err_string =
"OUT_OF_MEMORY";
203 case GL_STACK_OVERFLOW:
204 err_string =
"STACK_OVERFLOW";
206 case GL_STACK_UNDERFLOW:
207 err_string =
"STACK_UNDERFLOW";
213 std::cerr << file <<
" - " << line <<
": " << err_string <<
" - " << message << std::endl;
214 }
while(err != GL_NO_ERROR);
218 sys_info.platform_name = std::string(SDL_GetPlatform());
220 sys_info.num_logical_cores = SDL_GetCPUCount();
221 sys_info.system_ram = SDL_GetSystemRAM();
223 sys_info.num_displays = SDL_GetNumVideoDisplays();
226 for(
int i = 0; i <
sys_info.num_displays; i++) {
227 int num_modes = SDL_GetNumDisplayModes(i);
228 sys_info.supported_display_modes[i].resize(num_modes);
229 SDL_GetDesktopDisplayMode(i, &
sys_info.desktop_display_modes[i]);
230 for(
int j = 0; j < num_modes; j++)
231 SDL_GetDisplayMode(i, j, &
sys_info.supported_display_modes[i][j]);
234 for(
int i = 0; i <
sys_info.num_displays; i++)
235 SDL_GetDisplayBounds(i, &
sys_info.display_bounds[i]);
Handles library initialization and provides system information.
static void get_sys_info()
Gathers system information and populates the sys_info attribute.
static std::vector< std::string > error_string
A list of all error strings.
static void set_gl_version(int major, int minor)
Sets the OpenGL version.
static bool gl_version_manual
True if set_gl_version was called, false otherwise.
static bool init()
Initializes SGLTK.
static void _check_error(std::string message, std::string file, unsigned int line)
Outputs OpenGL error messages.
static bool enable_vsync(bool on)
Turns VSync on or off.
static struct SYS_INFO sys_info
System information.
static void set_depth_stencil_size(int depth_size, int stencil_size)
Sets the size of the depth and stencil buffers.
static bool chdir_to_bin(char **argv)
Changes the current working directory to the directory containing the executable.
static void enable_screensaver(bool enable)
Enables the screensaver.
static bool init_glew()
Initializes GLEW.
static bool init_img()
Initializes SDL2_img.
static void quit()
Deinitializes SGLTK.
static void quit_sdl()
Deinitializes SDL2.
static void quit_img()
Deinitializes SDL2_img.
static bool init_sdl()
Initializes SDL2.
static void set_msaa_sample_number(int number_samples)
Sets the number of samples used for multisample anti-aliasing.