]> git.localhorst.tv Git - tacos.git/blob - src/app/init.cpp
basic floor idea
[tacos.git] / src / app / init.cpp
1 #include "init.hpp"
2
3 #include "config.hpp"
4 #include "error.hpp"
5
6 #include <alut.h>
7 #include <SDL.h>
8 #include <SDL_image.h>
9 #include <SDL_ttf.h>
10
11
12 namespace tacos {
13
14 InitAlut::InitAlut() {
15         if (!alutInit(nullptr, nullptr)) {
16                 throw AlutError("alutInit(nullptr, nullptr)");
17         }
18 }
19
20 InitAlut::~InitAlut() {
21         if (!alutExit()) {
22                 throw AlutError("alutExit()");
23         }
24 }
25
26
27 InitGL::InitGL(bool double_buffer, int multi_sample) {
28         if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3) != 0) {
29                 throw SDLError("SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3)");
30         }
31         if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3) != 0) {
32                 throw SDLError("SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3)");
33         }
34         if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE) != 0) {
35                 throw SDLError("SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE)");
36         }
37
38         if (!double_buffer) {
39                 if (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0) != 0) {
40                         throw SDLError("SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0)");
41                 }
42         }
43
44         if (multi_sample > 1) {
45                 if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1) != 0) {
46                         throw SDLError("SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1)");
47                 }
48                 if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, multi_sample) != 0) {
49                         throw SDLError("SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, x)");
50                 }
51         }
52 }
53
54
55 InitIMG::InitIMG() {
56         if (IMG_Init(IMG_INIT_PNG) == 0) {
57                 throw SDLError("IMG_Init(IMG_INIT_PNG)");
58         }
59 }
60
61 InitIMG::~InitIMG() noexcept {
62         IMG_Quit();
63 }
64
65
66 InitSDL::InitSDL() {
67         if (SDL_Init(SDL_INIT_VIDEO) != 0) {
68                 throw SDLError("SDL_Init(SDL_INIT_VIDEO)");
69         }
70         // SDL seems to start out in text input state
71         SDL_StopTextInput();
72 }
73
74 InitSDL::~InitSDL() noexcept {
75         SDL_Quit();
76 }
77
78
79 InitTTF::InitTTF() {
80         if (TTF_Init() != 0) {
81                 throw SDLError("TTF_Init()");
82         }
83 }
84
85 InitTTF::~InitTTF() noexcept {
86         TTF_Quit();
87 }
88
89
90 Init::Init(const Config &config)
91 : sdl()
92 , gl(config.double_buffer, config.multi_sample)
93 , img()
94 , ttf()
95 , alut() {
96
97 }
98
99 }