]> git.localhorst.tv Git - blobs.git/blobdiff - src/app/app.cpp
basic sky box
[blobs.git] / src / app / app.cpp
index f847a79176701f174a60bdaf323b5efda252320f..0f50aa75d00104a21fe5a32a988bef297a98580f 100644 (file)
@@ -175,6 +175,7 @@ Assets::Assets()
 , data_path(path + "data/")
 , font_path(path + "fonts/")
 , skin_path(path + "skins/")
+, sky_path(path + "skies/")
 , tile_path(path + "tiles/")
 , random(0x6283B64CEFE57925)
 , fonts{
@@ -223,6 +224,11 @@ Assets::Assets()
        LoadSkinTexture("spots", textures.skins, 4);
        LoadSkinTexture("circles", textures.skins, 5);
        textures.skins.FilterTrilinear();
+
+       textures.sky.Bind();
+       LoadSkyTexture("blue", textures.sky);
+       textures.sky.FilterTrilinear();
+       textures.sky.WrapEdge();
 }
 
 Assets::~Assets() {
@@ -385,5 +391,71 @@ void Assets::LoadSkinTexture(const string &name, graphics::ArrayTexture &tex, in
        SDL_FreeSurface(srf);
 }
 
+void Assets::LoadSkyTexture(const string &name, graphics::CubeMap &cm) const {
+       string full = sky_path + 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";
+
+       SDL_Surface *srf = nullptr;
+
+       if (!(srf = IMG_Load(right.c_str()))) throw SDLError("IMG_Load");
+       try {
+               cm.Data(graphics::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(graphics::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(graphics::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(graphics::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(graphics::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(graphics::CubeMap::FRONT, *srf);
+       } catch (...) {
+               SDL_FreeSurface(srf);
+               throw;
+       }
+       SDL_FreeSurface(srf);
+}
+
 }
 }