]> git.localhorst.tv Git - blobs.git/blobdiff - src/app/app.cpp
some texture
[blobs.git] / src / app / app.cpp
index 064786fb82baf42403588ec4f789c23b3e1f6d2e..8c0f8e13521547cd16624e3d793926064ed50b90 100644 (file)
@@ -6,6 +6,7 @@
 #include "../graphics/Viewport.hpp"
 
 #include <SDL.h>
+#include <SDL_image.h>
 
 
 namespace blobs {
@@ -164,22 +165,40 @@ void State::OnQuit() {
 }
 
 
-Assets::Assets() {
+Assets::Assets()
+: path("assets/")
+, tile_path(path + "tiles/") {
        graphics::Format format;
        textures.tiles.Bind();
-       textures.tiles.Reserve(1, 1, 3, format);
-       std::uint8_t texdata[] = {
-               0xFF, 0x00, 0x00, 0xFF,
-               0x00, 0xFF, 0x00, 0xFF,
-               0x00, 0x00, 0xFF, 0xFF,
-       };
-       textures.tiles.Data(0, format, texdata);
-       textures.tiles.Data(1, format, texdata + 4);
-       textures.tiles.Data(2, format, texdata + 8);
+       textures.tiles.Reserve(256, 256, 9, format);
+       LoadTileTexture("1", textures.tiles, 0);
+       LoadTileTexture("2", textures.tiles, 1);
+       LoadTileTexture("3", textures.tiles, 2);
+       LoadTileTexture("4", textures.tiles, 3);
+       LoadTileTexture("5", textures.tiles, 4);
+       LoadTileTexture("6", textures.tiles, 5);
+       LoadTileTexture("7", textures.tiles, 6);
+       LoadTileTexture("8", textures.tiles, 7);
+       LoadTileTexture("9", textures.tiles, 8);
 }
 
 Assets::~Assets() {
 }
 
+void Assets::LoadTileTexture(const std::string &name, graphics::ArrayTexture &tex, int layer) const {
+       std::string path = tile_path + name + ".png";
+       SDL_Surface *srf = IMG_Load(path.c_str());
+       if (!srf) {
+               throw SDLError("IMG_Load");
+       }
+       try {
+               tex.Data(layer, *srf);
+       } catch (...) {
+               SDL_FreeSurface(srf);
+               throw;
+       }
+       SDL_FreeSurface(srf);
+}
+
 }
 }