diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2022-06-25 15:20:26 +0200 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-06-25 15:20:26 +0200 |
| commit | 274c548274d9fcbb1cd9fca5b522f8a6cc8869d2 (patch) | |
| tree | 1b0e94ffd75d41ef9504ad4ef5c32ab4246bc9df /texture-atlas.hpp | |
| parent | dad4ae54192bd420aaf7b8816a953c0e42a93dd6 (diff) | |
.
Diffstat (limited to 'texture-atlas.hpp')
| -rw-r--r-- | texture-atlas.hpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/texture-atlas.hpp b/texture-atlas.hpp new file mode 100644 index 00000000..e7f8a260 --- /dev/null +++ b/texture-atlas.hpp @@ -0,0 +1,31 @@ +#pragma once +#include <Magnum/Magnum.h> +#include <Magnum/GL/Texture.h> +#include <array> + +namespace Magnum::Examples { + +struct texture_atlas final +{ + using vertex_array_type = std::array<Vector3, 4>; + + texture_atlas(const ImageView2D& img, Vector2i dims); + std::array<Vector2, 4> texcoords_for_id(int id) const; + static vertex_array_type floor_quad(Vector3 center, Vector2 size); + static vertex_array_type wall_quad_S(Vector3 center, Vector3 size); + static vertex_array_type wall_quad_E(Vector3 center, Vector3 size); + static vertex_array_type wall_quad_N(Vector3 center, Vector3 size); + static vertex_array_type wall_quad_W(Vector3 center, Vector3 size); + static std::array<UnsignedShort, 6> indices(int N); + GL::Texture2D& texture() { return tex_; } + constexpr int size() const { return dims_.product(); } + constexpr Vector2i tile_size() const { return tile_size_; } + + texture_atlas(const texture_atlas&) = delete; + texture_atlas& operator=(const texture_atlas&) = delete; +private: + GL::Texture2D tex_; + Vector2i size_, dims_, tile_size_; +}; + +} // namespace Magnum::Examples |
