]> git.localhorst.tv Git - blank.git/blobdiff - src/app/init.cpp
move RandomWalk into new "ai" module
[blank.git] / src / app / init.cpp
index 1cc0c2485b50db7e79a5fdd5baf242ef4201a72d..18816a424bdb3a972341311d72a9cda19fa19ac6 100644 (file)
@@ -1,6 +1,7 @@
 #include "init.hpp"
 
 #include <algorithm>
+#include <alut.h>
 #include <SDL.h>
 #include <SDL_image.h>
 #include <SDL_ttf.h>
@@ -19,10 +20,30 @@ std::string sdl_error_append(std::string msg) {
        return msg;
 }
 
+std::string alut_error_append(ALenum num, std::string msg) {
+       const char *error = alutGetErrorString(num);
+       if (*error != '\0') {
+               msg += ": ";
+               msg += error;
+       }
+       return msg;
+}
+
 }
 
 namespace blank {
 
+AlutError::AlutError(ALenum num)
+: std::runtime_error(alutGetErrorString(num)) {
+
+}
+
+AlutError::AlutError(ALenum num, const std::string &msg)
+: std::runtime_error(alut_error_append(num, msg)) {
+
+}
+
+
 SDLError::SDLError()
 : std::runtime_error(SDL_GetError()) {
 
@@ -67,6 +88,19 @@ InitTTF::~InitTTF() {
 }
 
 
+InitAL::InitAL() {
+       if (!alutInit(nullptr, nullptr)) {
+               throw AlutError(alutGetError(), "alutInit");
+       }
+}
+
+InitAL::~InitAL() {
+       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)");