From d0a3b0d4401917dd02ad27b4f9a4b91699569e36 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 2 Oct 2022 00:56:41 +0200 Subject: a --- tile-mesh.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tile-mesh.cpp (limited to 'tile-mesh.cpp') diff --git a/tile-mesh.cpp b/tile-mesh.cpp new file mode 100644 index 00000000..c1f819d8 --- /dev/null +++ b/tile-mesh.cpp @@ -0,0 +1,31 @@ +#include "tile-mesh.hpp" +#include "tile-shader.hpp" +#include "tile.hpp" + +namespace Magnum::Examples { + +tile_mesh::tile_mesh() +{ + _mesh.setCount((int)index_count) + .addVertexBuffer(_vertex_buffer, 0, + tile_shader::Position{}, tile_shader::TextureCoordinates{}) + .setIndexBuffer(_index_buffer, 0, GL::MeshIndexType::UnsignedShort); +} + +void tile_mesh::draw_quad(tile_shader& shader, tile_image& img, const std::array& positions) +{ + auto texcoords = img.atlas->texcoords_for_id(img.variant); + //auto positions = img.atlas->floor_quad(position, { TILE_SIZE[0], TILE_SIZE[1] }); + for (std::size_t i = 0; i < 4; i++) + _vertex_data[i] = {positions[i], texcoords[i]}; + img.atlas->texture().bind(0); + _vertex_buffer.setData(_vertex_data, Magnum::GL::BufferUsage::DynamicDraw); + shader.draw(_mesh); +} + +void tile_mesh::draw_floor_quad(tile_shader& shader, tile_image& img, Vector3 center) +{ + draw_quad(shader, img, img.atlas->floor_quad(center, { TILE_SIZE[0], TILE_SIZE[1] })); +} + +} // namespace Magnum::Examples -- cgit v1.2.3