summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--shaders/tile-shader.frag2
-rw-r--r--tile-atlas.cpp13
-rw-r--r--tile-atlas.hpp6
-rw-r--r--tile.hpp2
-rw-r--r--wall-mesh.cpp3
-rw-r--r--wall-mesh.hpp2
6 files changed, 15 insertions, 13 deletions
diff --git a/shaders/tile-shader.frag b/shaders/tile-shader.frag
index beddd43d..84bcac45 100644
--- a/shaders/tile-shader.frag
+++ b/shaders/tile-shader.frag
@@ -1,6 +1,6 @@
precision highp float;
-uniform sampler2D sampler;
+uniform sampler2DRect sampler;
noperspective in vec2 frag_texcoords;
out vec4 color;
diff --git a/tile-atlas.cpp b/tile-atlas.cpp
index 6b7a203e..21dcc57f 100644
--- a/tile-atlas.cpp
+++ b/tile-atlas.cpp
@@ -14,12 +14,12 @@ tile_atlas::tile_atlas(const Containers::StringView& name, const ImageView2D& im
CORRADE_INTERNAL_ASSERT(size_ % dims_ == Vector2i{});
CORRADE_INTERNAL_ASSERT(dims.product() < 256);
CORRADE_INTERNAL_ASSERT(tile_size() * dims_ == size_);
- tex_.setWrapping(GL::SamplerWrapping::ClampToEdge)
+ tex_.setWrapping(GL::SamplerWrapping::Repeat)
.setMagnificationFilter(GL::SamplerFilter::Nearest)
- .setMinificationFilter(GL::SamplerFilter::Linear)
+ .setMinificationFilter(GL::SamplerFilter::Nearest)
.setMaxAnisotropy(0)
- .setStorage(1, GL::textureFormat(image.format()), image.size())
- .setSubImage(0, {}, image);
+ .setStorage(GL::textureFormat(image.format()), image.size())
+ .setSubImage({}, image);
}
std::array<Vector2, 4> tile_atlas::texcoords_for_id(std::size_t id2) const
@@ -28,8 +28,9 @@ std::array<Vector2, 4> tile_atlas::texcoords_for_id(std::size_t id2) const
auto id_ = (int)id2;
ASSERT(id_ >= 0 && id_ < dims_.product());
Vector2i id = { id_ % dims_[0], id_ / dims_[0] };
- auto p0 = Vector2(id * tile_size_) / Vector2(size_);
- auto p1 = Vector2(tile_size_) / Vector2(size_);
+ constexpr Vector2 half{.5f, .5f};
+ auto p0 = Vector2(id * tile_size_) + half;
+ auto p1 = Vector2(tile_size_);
auto x0 = p0.x(), x1 = p1.x(), y0 = p0.y(), y1 = p1.y();
return {{
{ x0+x1, y0+y1 }, // bottom right
diff --git a/tile-atlas.hpp b/tile-atlas.hpp
index f2cacf09..759cd6c7 100644
--- a/tile-atlas.hpp
+++ b/tile-atlas.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "compat/assert.hpp"
#include <Magnum/Magnum.h>
-#include <Magnum/GL/Texture.h>
+#include <Magnum/GL/RectangleTexture.h>
#include <array>
#include <string>
@@ -21,11 +21,11 @@ struct tile_atlas final
std::size_t size() const { return (std::size_t)dims_.product(); }
Vector2i tile_size() const { return size_ / dims_; }
Vector2i dimensions() const { return dims_; }
- GL::Texture2D& texture() { return tex_; }
+ GL::RectangleTexture& texture() { return tex_; }
std::string name() const { return name_; }
private:
- GL::Texture2D tex_;
+ GL::RectangleTexture tex_;
std::string name_;
Vector2i size_, dims_;
};
diff --git a/tile.hpp b/tile.hpp
index 9a5db20c..261c50ee 100644
--- a/tile.hpp
+++ b/tile.hpp
@@ -8,7 +8,7 @@
namespace Magnum::Examples {
struct tile_atlas;
-constexpr inline Vector3 TILE_SIZE = { 50, 50, 50 };
+constexpr inline Vector3 TILE_SIZE = { 64, 64, 64 };
constexpr inline std::size_t TILE_MAX_DIM = 16;
constexpr inline std::size_t TILE_COUNT = TILE_MAX_DIM*TILE_MAX_DIM;
diff --git a/wall-mesh.cpp b/wall-mesh.cpp
index a27d34af..ee998e63 100644
--- a/wall-mesh.cpp
+++ b/wall-mesh.cpp
@@ -2,6 +2,7 @@
#include "tile-atlas.hpp"
#include "shaders/tile-shader.hpp"
#include "chunk.hpp"
+#include <Magnum/GL/RectangleTexture.h>
#include <Magnum/GL/MeshView.h>
namespace Magnum::Examples {
@@ -53,7 +54,7 @@ void wall_mesh::draw(tile_shader& shader, chunk& c)
_vertex_buffer.setSubData(0, Containers::arrayView(data.data(), pos));
}
- const GL::Texture2D* last_texture = nullptr;
+ const GL::RectangleTexture* last_texture = nullptr;
Magnum::GL::MeshView mesh{_mesh};
for (std::size_t i = 0; i < pos; i++)
{
diff --git a/wall-mesh.hpp b/wall-mesh.hpp
index 9356f384..ce1ff30a 100644
--- a/wall-mesh.hpp
+++ b/wall-mesh.hpp
@@ -31,7 +31,7 @@ private:
using quad = std::array<vertex, 4>;
using vertex_array = std::array<quad, COUNT>;
- using texture_array = std::array<GL::Texture2D*, COUNT>;
+ using texture_array = std::array<GL::RectangleTexture*, COUNT>;
static void maybe_add_tile(vertex_array& data, texture_array& textures, std::size_t& pos,
tile& x, local_coords pt);