#include "init.hpp"
#include <algorithm>
+#include <alut.h>
#include <SDL.h>
#include <SDL_image.h>
+#include <SDL_net.h>
#include <SDL_ttf.h>
+#include <string>
#include <GL/glew.h>
-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);
}
}
+InitNet::InitNet() {
+ if (SDLNet_Init() != 0) {
+ throw SDLError("SDLNet_Init()");
+ }
+}
+
+InitNet::~InitNet() {
+ SDLNet_Quit();
+}
+
+
InitTTF::InitTTF() {
if (TTF_Init() != 0) {
throw SDLError("TTF_Init()");
}
+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)");
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)");
}
}
}
-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)