sgltk 0.6
Simple OpenGL Tool Kit
Loading...
Searching...
No Matches
app.h
Go to the documentation of this file.
1#ifndef __APP_H__
2#define __APP_H__
4
9#define check_gl_error(message) do{\
10 sgltk::App::_check_error(message, __FILE__, __LINE__);\
11} while(0)
12
13#ifdef _WIN32
14 #ifdef MAKE_LIB //building sgltk
15 #ifdef MAKE_DLL //dynamic
16 #define EXPORT __declspec(dllexport)
17 #elif MAKE_STATIC //static
18 #define EXPORT
19 #endif //MAKE_DLL
20 #else //linking with sgltk
21 #ifndef SGLTK_STATIC //dynamic
22 #define EXPORT __declspec(dllimport)
23 #else //static
24 #define EXPORT
25 #endif
26 #endif //MAKE_LIB
27#else //linux
28 #define EXPORT
29#endif //_WIN32
30
31#include "config.h"
32
33#include <GL/glew.h>
34
35#include <string>
36#include <chrono>
37#include <thread>
38#include <fstream>
39#include <iostream>
40#include <map>
41#include <memory>
42#include <list>
43#include <vector>
44#include <algorithm>
45#include <exception>
46
47#ifdef _WIN32 //windows
48 #include <direct.h>
49#else //linux
50 #include <unistd.h>
51#endif //_WIN32
52
53#define GLM_FORCE_RADIANS
54#define GLM_ENABLE_EXPERIMENTAL
55#include <glm/glm.hpp>
56#include <glm/gtc/type_ptr.hpp>
57#include <glm/gtx/transform.hpp>
58#include <glm/gtc/matrix_transform.hpp>
59
60#define SDL_MAIN_HANDLED
61#ifdef SDL_ALT_PATH
62 #include <SDL2/SDL.h>
63 #ifdef HAVE_SDL_TTF_H
64 #include <SDL2/SDL_ttf.h>
65 #endif //HAVE_SDL_TTF_H
66 #include <SDL2/SDL_image.h>
67 #include <SDL2/SDL_opengl.h>
68#else
69 #include <SDL.h>
70 #ifdef HAVE_SDL_TTF_H
71 #include <SDL_ttf.h>
72 #endif //HAVE_SDL_TTF_H
73 #include <SDL_image.h>
74 #include <SDL_opengl.h>
75#endif
76
77#ifdef HAVE_ASSIMP_H
78 #include <assimp/Importer.hpp>
79 #include <assimp/scene.h>
80 #include <assimp/postprocess.h>
81#endif //HAVE_ASSIMP_H
82
83namespace sgltk {
84
88struct SYS_INFO {
92 std::string platform_name;
108 std::vector<SDL_DisplayMode> desktop_display_modes;
113 std::vector<std::vector<SDL_DisplayMode> > supported_display_modes;
117 std::vector<SDL_Rect> display_bounds;
126};
127
128
133class App {
134 static bool initialized;
135
136 EXPORT App();
137 EXPORT ~App();
138
139public:
143 EXPORT static bool gl_version_manual;
147 EXPORT static struct SYS_INFO sys_info;
151 EXPORT static std::vector<std::string> error_string;
156 EXPORT static bool init();
160 EXPORT static void quit();
165 EXPORT static bool init_glew();
170 EXPORT static bool init_img();
174 EXPORT static void quit_img();
179 EXPORT static bool init_sdl();
183 EXPORT static void quit_sdl();
184
185#ifdef HAVE_SDL_TTF_H
190 EXPORT static bool init_ttf();
194 EXPORT static void quit_ttf();
195#endif //HAVE_SDL_TTF_H
203 EXPORT static void set_gl_version(int major, int minor);
210 EXPORT static void set_depth_stencil_size(int depth_size, int stencil_size);
215 EXPORT static void set_msaa_sample_number(int number_samples);
220 EXPORT static void enable_screensaver(bool enable);
226 EXPORT static bool enable_vsync(bool on);
234 EXPORT static bool chdir_to_bin(char **argv);
238 EXPORT static void get_sys_info();
245 EXPORT static void _check_error(std::string message, std::string file, unsigned int line);
246
247};
248
249};
250
251#endif
static void get_sys_info()
Gathers system information and populates the sys_info attribute.
Definition app.cpp:217
static std::vector< std::string > error_string
A list of all error strings.
Definition app.h:151
static void set_gl_version(int major, int minor)
Sets the OpenGL version.
Definition app.cpp:89
static bool gl_version_manual
True if set_gl_version was called, false otherwise.
Definition app.h:143
static bool init()
Initializes SGLTK.
Definition app.cpp:64
static void _check_error(std::string message, std::string file, unsigned int line)
Outputs OpenGL error messages.
Definition app.cpp:181
static bool enable_vsync(bool on)
Turns VSync on or off.
Definition app.cpp:144
static struct SYS_INFO sys_info
System information.
Definition app.h:147
static void set_depth_stencil_size(int depth_size, int stencil_size)
Sets the size of the depth and stencil buffers.
Definition app.cpp:117
static bool chdir_to_bin(char **argv)
Changes the current working directory to the directory containing the executable.
Definition app.cpp:158
static void enable_screensaver(bool enable)
Enables the screensaver.
Definition app.cpp:137
static bool init_glew()
Initializes GLEW.
Definition app.cpp:10
static bool init_img()
Initializes SDL2_img.
Definition app.cpp:19
static void quit()
Deinitializes SGLTK.
Definition app.cpp:127
static void quit_sdl()
Deinitializes SDL2.
Definition app.cpp:45
static void quit_img()
Deinitializes SDL2_img.
Definition app.cpp:29
static bool init_sdl()
Initializes SDL2.
Definition app.cpp:33
static void set_msaa_sample_number(int number_samples)
Sets the number of samples used for multisample anti-aliasing.
Definition app.cpp:122
System information.
Definition app.h:88
std::vector< SDL_DisplayMode > desktop_display_modes
The display modes of each display.
Definition app.h:108
std::string platform_name
The name of the platform.
Definition app.h:92
int max_patch_vertices
The maximum number of vertices in a patch.
Definition app.h:121
int max_tess_level
The maximum supported tessellation level.
Definition app.h:125
int num_logical_cores
The number of logical cores.
Definition app.h:96
int system_ram
The amount of ram in MB.
Definition app.h:100
std::vector< SDL_Rect > display_bounds
Display bounds.
Definition app.h:117
int num_displays
The number of displays.
Definition app.h:104
std::vector< std::vector< SDL_DisplayMode > > supported_display_modes
A list of other supported display modes for every detected display.
Definition app.h:113