X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Finit.cpp;h=dfadffe16f0c1591dc76810a47c7dfbeae3c6463;hb=HEAD;hp=1cc0c2485b50db7e79a5fdd5baf242ef4201a72d;hpb=5d2da8a07411ad6417d6ed8d1be997189cf5ce89;p=blank.git diff --git a/src/app/init.cpp b/src/app/init.cpp index 1cc0c24..dfadffe 100644 --- a/src/app/init.cpp +++ b/src/app/init.cpp @@ -1,47 +1,38 @@ #include "init.hpp" #include +#include #include #include +#include #include +#include #include -namespace { - -std::string sdl_error_append(std::string msg) { - const char *error = SDL_GetError(); - if (*error != '\0') { - msg += ": "; - msg += error; - SDL_ClearError(); - } - return msg; -} - -} - namespace blank { -SDLError::SDLError() -: std::runtime_error(SDL_GetError()) { - +InitSDL::InitSDL() { + if (SDL_Init(SDL_INIT_EVENTS) != 0) { + throw SDLError("SDL_Init(SDL_INIT_EVENTS)"); + } } -SDLError::SDLError(const std::string &msg) -: std::runtime_error(sdl_error_append(msg)) { - +InitSDL::~InitSDL() { + SDL_Quit(); } -InitSDL::InitSDL() { - if (SDL_Init(SDL_INIT_VIDEO) != 0) { - throw SDLError("SDL_Init(SDL_INIT_VIDEO)"); +InitVideo::InitVideo() { + if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) { + throw SDLError("SDL_InitSubSystem(SDL_INIT_VIDEO)"); } + // SDL seems to start out in text input state + SDL_StopTextInput(); } -InitSDL::~InitSDL() { - SDL_Quit(); +InitVideo::~InitVideo() { + SDL_QuitSubSystem(SDL_INIT_VIDEO); } @@ -56,6 +47,17 @@ InitIMG::~InitIMG() { } +InitNet::InitNet() { + if (SDLNet_Init() != 0) { + throw SDLError("SDLNet_Init()"); + } +} + +InitNet::~InitNet() { + SDLNet_Quit(); +} + + InitTTF::InitTTF() { if (TTF_Init() != 0) { throw SDLError("TTF_Init()"); @@ -67,6 +69,19 @@ InitTTF::~InitTTF() { } +InitAL::InitAL() { + if (!alutInit(nullptr, nullptr)) { + throw AlutError(alutGetError(), "alutInit"); + } +} + +InitAL::~InitAL() throw(AlutError) { + if (!alutExit()) { + throw AlutError(alutGetError(), "alutExit"); + } +} + + InitGL::InitGL(bool double_buffer, int sample_size) { if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3) != 0) { throw SDLError("SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3)"); @@ -78,9 +93,9 @@ InitGL::InitGL(bool double_buffer, int sample_size) { throw SDLError("SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE)"); } - if (double_buffer) { - if (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) != 0) { - throw SDLError("SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1)"); + if (!double_buffer) { + if (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0) != 0) { + throw SDLError("SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0)"); } } @@ -164,8 +179,14 @@ InitGLEW::InitGLEW() { } -Init::Init(bool double_buffer, int sample_size) +InitHeadless::InitHeadless() : init_sdl() +, init_net() { + +} + +Init::Init(bool double_buffer, int sample_size) +: init_video() , init_img() , init_ttf() , init_gl(double_buffer, sample_size)