X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Fapp.cpp;h=4d2d2c098afa17bcde96083ddf384aeddacaa86b;hb=2e3774eb3f2d5d23a08731175b168566457e2192;hp=4368022eb59dbddc5c981f9e5e172af4af8f56cf;hpb=1afc887a2040dfdedfa66913e94ff7a9634f648f;p=blank.git diff --git a/src/app/app.cpp b/src/app/app.cpp index 4368022..4d2d2c0 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -9,6 +9,7 @@ #include "init.hpp" #include "../audio/Sound.hpp" #include "../graphics/ArrayTexture.hpp" +#include "../graphics/CubeMap.hpp" #include "../graphics/Font.hpp" #include "../graphics/Texture.hpp" #include "../io/TokenStreamReader.hpp" @@ -374,6 +375,79 @@ void AssetLoader::LoadBlockTypes(const std::string &set_name, BlockTypeRegistry } } +CubeMap AssetLoader::LoadCubeMap(const string &name) const { + string full = textures + name; + string right = full + "-right.png"; + string left = full + "-left.png"; + string top = full + "-top.png"; + string bottom = full + "-bottom.png"; + string back = full + "-back.png"; + string front = full + "-front.png"; + + CubeMap cm; + cm.Bind(); + SDL_Surface *srf; + + if (!(srf = IMG_Load(right.c_str()))) throw SDLError("IMG_Load"); + try { + cm.Data(CubeMap::RIGHT, *srf); + } catch (...) { + SDL_FreeSurface(srf); + throw; + } + SDL_FreeSurface(srf); + + if (!(srf = IMG_Load(left.c_str()))) throw SDLError("IMG_Load"); + try { + cm.Data(CubeMap::LEFT, *srf); + } catch (...) { + SDL_FreeSurface(srf); + throw; + } + SDL_FreeSurface(srf); + + if (!(srf = IMG_Load(top.c_str()))) throw SDLError("IMG_Load"); + try { + cm.Data(CubeMap::TOP, *srf); + } catch (...) { + SDL_FreeSurface(srf); + throw; + } + SDL_FreeSurface(srf); + + if (!(srf = IMG_Load(bottom.c_str()))) throw SDLError("IMG_Load"); + try { + cm.Data(CubeMap::BOTTOM, *srf); + } catch (...) { + SDL_FreeSurface(srf); + throw; + } + SDL_FreeSurface(srf); + + if (!(srf = IMG_Load(back.c_str()))) throw SDLError("IMG_Load"); + try { + cm.Data(CubeMap::BACK, *srf); + } catch (...) { + SDL_FreeSurface(srf); + throw; + } + SDL_FreeSurface(srf); + + if (!(srf = IMG_Load(front.c_str()))) throw SDLError("IMG_Load"); + try { + cm.Data(CubeMap::FRONT, *srf); + } catch (...) { + SDL_FreeSurface(srf); + throw; + } + SDL_FreeSurface(srf); + + cm.FilterNearest(); + cm.WrapEdge(); + + return cm; +} + Font AssetLoader::LoadFont(const string &name, int size) const { string full = fonts + name + ".ttf"; return Font(full.c_str(), size);