--- /dev/null
+#include "init.hpp"
+
+#include "error.hpp"
+
+#include <alut.h>
+#include <SDL.h>
+#include <SDL_image.h>
+#include <SDL_ttf.h>
+
+
+namespace tacos {
+
+InitAlut::InitAlut() {
+ if (!alutInit(nullptr, nullptr)) {
+ throw AlutError("alutInit(nullptr, nullptr)");
+ }
+}
+
+InitAlut::~InitAlut() {
+ if (!alutExit()) {
+ throw AlutError("alutExit()");
+ }
+}
+
+
+InitGL::InitGL(bool double_buffer, int multi_sample) {
+ if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3) != 0) {
+ throw SDLError("SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3)");
+ }
+ if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3) != 0) {
+ throw SDLError("SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3)");
+ }
+ if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE) != 0) {
+ 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, 0) != 0) {
+ throw SDLError("SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0)");
+ }
+ }
+
+ if (multi_sample > 1) {
+ if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1) != 0) {
+ throw SDLError("SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1)");
+ }
+ if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, multi_sample) != 0) {
+ throw SDLError("SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, x)");
+ }
+ }
+}
+
+
+InitIMG::InitIMG() {
+ if (IMG_Init(IMG_INIT_PNG) == 0) {
+ throw SDLError("IMG_Init(IMG_INIT_PNG)");
+ }
+}
+
+InitIMG::~InitIMG() noexcept {
+ IMG_Quit();
+}
+
+
+InitSDL::InitSDL() {
+ if (SDL_Init(SDL_INIT_VIDEO) != 0) {
+ throw SDLError("SDL_Init(SDL_INIT_VIDEO)");
+ }
+ // SDL seems to start out in text input state
+ SDL_StopTextInput();
+}
+
+InitSDL::~InitSDL() noexcept {
+ SDL_Quit();
+}
+
+
+InitTTF::InitTTF() {
+ if (TTF_Init() != 0) {
+ throw SDLError("TTF_Init()");
+ }
+}
+
+InitTTF::~InitTTF() noexcept {
+ TTF_Quit();
+}
+
+}