]> git.localhorst.tv Git - blobs.git/commitdiff
some texture
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 13 Nov 2017 21:11:49 +0000 (22:11 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 13 Nov 2017 21:11:49 +0000 (22:11 +0100)
assets
src/app/Assets.hpp
src/app/app.cpp
src/world/world.cpp

diff --git a/assets b/assets
index 44941807e0e738083d2e2e79aeae3f06b0f7fcc2..a8e34c508dc619ed8643875431baac64d88765b2 160000 (submodule)
--- a/assets
+++ b/assets
@@ -1 +1 @@
-Subproject commit 44941807e0e738083d2e2e79aeae3f06b0f7fcc2
+Subproject commit a8e34c508dc619ed8643875431baac64d88765b2
index c80726a07c05adbd50058e6a41d6eea65e18cca9..b95ee48ea4f75a615cbee85d93a83e5ace754f3a 100644 (file)
@@ -5,12 +5,17 @@
 #include "../graphics/PlanetSurface.hpp"
 #include "../graphics/SunSurface.hpp"
 
+#include <string>
+
 
 namespace blobs {
 namespace app {
 
 struct Assets {
 
+       std::string path;
+       std::string tile_path;
+
        struct {
                graphics::ArrayTexture tiles;
        } textures;
@@ -29,6 +34,8 @@ struct Assets {
        Assets(Assets &&) = delete;
        Assets &operator =(Assets &&) = delete;
 
+       void LoadTileTexture(const std::string &name, graphics::ArrayTexture &, int layer) const;
+
 };
 
 }
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);
+}
+
 }
 }
index 5ba96732596c8657b176db6e6faa8a0c811c51b3..b872503c185b928df0d6175a0eb059c3518cbde6 100644 (file)
@@ -277,32 +277,34 @@ void Planet::BuildVAOs() {
                        for (int y = 0; y < sidelength; ++y) {
                                for (int x = 0; x < sidelength; ++x, ++index) {
                                        float tex = TileAt(surface, x, y).type;
+                                       const float tex_u_begin = surface < 3 ? 1.0f : 0.0f;
+                                       const float tex_u_end = surface < 3 ? 0.0f : 1.0f;
                                        attrib[4 * index + 0].position[(surface + 0) % 3] = x + 0 - offset;
                                        attrib[4 * index + 0].position[(surface + 1) % 3] = y + 0 - offset;
                                        attrib[4 * index + 0].position[(surface + 2) % 3] = surface < 3 ? offset : -offset;
-                                       attrib[4 * index + 0].tex_coord[0] = 0.0f;
-                                       attrib[4 * index + 0].tex_coord[1] = 0.0f;
+                                       attrib[4 * index + 0].tex_coord[0] = tex_u_begin;
+                                       attrib[4 * index + 0].tex_coord[1] = 1.0f;
                                        attrib[4 * index + 0].tex_coord[2] = tex;
 
                                        attrib[4 * index + 1].position[(surface + 0) % 3] = x + 0 - offset;
                                        attrib[4 * index + 1].position[(surface + 1) % 3] = y + 1 - offset;
                                        attrib[4 * index + 1].position[(surface + 2) % 3] = surface < 3 ? offset : -offset;
-                                       attrib[4 * index + 1].tex_coord[0] = 0.0f;
+                                       attrib[4 * index + 1].tex_coord[0] = tex_u_end;
                                        attrib[4 * index + 1].tex_coord[1] = 1.0f;
                                        attrib[4 * index + 1].tex_coord[2] = tex;
 
                                        attrib[4 * index + 2].position[(surface + 0) % 3] = x + 1 - offset;
                                        attrib[4 * index + 2].position[(surface + 1) % 3] = y + 0 - offset;
                                        attrib[4 * index + 2].position[(surface + 2) % 3] = surface < 3 ? offset : -offset;
-                                       attrib[4 * index + 2].tex_coord[0] = 1.0f;
+                                       attrib[4 * index + 2].tex_coord[0] = tex_u_begin;
                                        attrib[4 * index + 2].tex_coord[1] = 0.0f;
                                        attrib[4 * index + 2].tex_coord[2] = tex;
 
                                        attrib[4 * index + 3].position[(surface + 0) % 3] = x + 1 - offset;
                                        attrib[4 * index + 3].position[(surface + 1) % 3] = y + 1 - offset;
                                        attrib[4 * index + 3].position[(surface + 2) % 3] = surface < 3 ? offset : -offset;
-                                       attrib[4 * index + 3].tex_coord[0] = 1.0f;
-                                       attrib[4 * index + 3].tex_coord[1] = 1.0f;
+                                       attrib[4 * index + 3].tex_coord[0] = tex_u_end;
+                                       attrib[4 * index + 3].tex_coord[1] = 0.0f;
                                        attrib[4 * index + 3].tex_coord[2] = tex;
                                }
                        }
@@ -363,7 +365,11 @@ void GenerateTest(Planet &p) {
        for (int surface = 0; surface <= 5; ++surface) {
                for (int y = 0; y < p.SideLength(); ++y) {
                        for (int x = 0; x < p.SideLength(); ++x) {
-                               p.TileAt(surface, x, y).type = (x == p.SideLength()/2) + (y == p.SideLength()/2);
+                               if (x == p.SideLength() / 2 && y == p.SideLength() / 2) {
+                                       p.TileAt(surface, x, y).type = surface;
+                               } else {
+                                       p.TileAt(surface, x, y).type = (x == p.SideLength()/2) + (y == p.SideLength()/2) + 6;
+                               }
                        }
                }
        }