diff options
-rw-r--r-- | floor-mesh.cpp | 1 | ||||
-rw-r--r-- | floor-mesh.hpp | 1 | ||||
-rw-r--r-- | main.cpp | 15 | ||||
-rw-r--r-- | shaders/tile-shader.vert | 2 | ||||
-rw-r--r-- | tile-atlas.cpp | 8 | ||||
-rw-r--r-- | tile.cpp | 1 | ||||
-rw-r--r-- | wall-mesh.cpp | 23 |
7 files changed, 17 insertions, 34 deletions
diff --git a/floor-mesh.cpp b/floor-mesh.cpp index defc318b..e1f3c744 100644 --- a/floor-mesh.cpp +++ b/floor-mesh.cpp @@ -2,6 +2,7 @@ #include "shaders/tile-shader.hpp" #include "tile.hpp" #include "chunk.hpp" +#include "tile-atlas.hpp" #include <Magnum/GL/MeshView.h> namespace Magnum::Examples { diff --git a/floor-mesh.hpp b/floor-mesh.hpp index edb3b403..e263a6ed 100644 --- a/floor-mesh.hpp +++ b/floor-mesh.hpp @@ -1,6 +1,5 @@ #pragma once #include "tile.hpp" -#include "tile-atlas.hpp" #include <array> #include <Corrade/Containers/ArrayViewStl.h> #include <Magnum/Magnum.h> @@ -84,8 +84,8 @@ chunk app::make_test_chunk() x.ground_image = { atlas, (std::uint8_t)(k % atlas->size()) }; }); c[{N/2 + 1, N/2}].wall_north = { wall1, 0 }; - c[{N/2 + 1, N/2 + 1}].wall_north = { wall1, 0 }; c[{N/2, N/2}].wall_north = { wall1, 0 }; + c[{N/2, N/2}].wall_west = { wall1, 0 }; return c; } @@ -158,10 +158,12 @@ app::app(const Arguments& arguments): void app::drawEvent() { GL::defaultFramebuffer.clear(GL::FramebufferClear::Color); - //GL::defaultFramebuffer.clear(GL::FramebufferClear::Depth); - //GL::Renderer::setDepthMask(true); - //GL::Renderer::setDepthFunction(GL::Renderer::DepthFunction::LessOrEqual); - //GL::Renderer::enable(GL::Renderer::Feature::DepthTest); +#if 1 + GL::defaultFramebuffer.clear(GL::FramebufferClear::Depth); + GL::Renderer::setDepthMask(true); + GL::Renderer::setDepthFunction(GL::Renderer::DepthFunction::LessOrEqual); + GL::Renderer::enable(GL::Renderer::Feature::DepthTest); +#endif update_window_scale(); { @@ -214,7 +216,8 @@ void app::do_camera(float dt) void app::reset_camera_offset() { - camera_offset = _shader.project({TILE_MAX_DIM*TILE_SIZE[0]/2.f, TILE_MAX_DIM*TILE_SIZE[1]/2.f, 0}); + //camera_offset = _shader.project({TILE_MAX_DIM*TILE_SIZE[0]/2.f, TILE_MAX_DIM*TILE_SIZE[1]/2.f, 0}); + camera_offset = {}; } void app::update(float dt) diff --git a/shaders/tile-shader.vert b/shaders/tile-shader.vert index dfab845e..fe81ba3b 100644 --- a/shaders/tile-shader.vert +++ b/shaders/tile-shader.vert @@ -11,6 +11,6 @@ void main() { frag_texcoords = texcoords; float cx = 2/scale.x, cy = 2/scale.y; - float x = position.y, y = position.x, z = position.z; + float x = -position.x, y = -position.y, z = position.z; gl_Position = vec4((x-y+offset.x)*cx, (x+y+z*2)*cx*0.75-offset.y*cx, 0, 1); } diff --git a/tile-atlas.cpp b/tile-atlas.cpp index 9d2f8070..e811ffc4 100644 --- a/tile-atlas.cpp +++ b/tile-atlas.cpp @@ -50,7 +50,7 @@ vertex_array_type tile_atlas::floor_quad(const Vector3 center, const Vector2 siz }}; } -vertex_array_type tile_atlas::wall_quad_N(const Vector3 center, const Vector3 size) +vertex_array_type tile_atlas::wall_quad_E(const Vector3 center, const Vector3 size) { float x = size[0]*.5f, y = size[1]*.5f, z = size[2]; return {{ @@ -61,7 +61,7 @@ vertex_array_type tile_atlas::wall_quad_N(const Vector3 center, const Vector3 si }}; } -vertex_array_type tile_atlas::wall_quad_E(const Vector3 center, const Vector3 size) +vertex_array_type tile_atlas::wall_quad_N(const Vector3 center, const Vector3 size) { float x = size[0]*.5f, y = size[1]*.5f, z = size[2]; return {{ @@ -72,7 +72,7 @@ vertex_array_type tile_atlas::wall_quad_E(const Vector3 center, const Vector3 si }}; } -vertex_array_type tile_atlas::wall_quad_S(const Vector3 center, const Vector3 size) +vertex_array_type tile_atlas::wall_quad_W(const Vector3 center, const Vector3 size) { float x = size[0]*.5f, y = size[1]*.5f, z = size[2]; return {{ @@ -83,7 +83,7 @@ vertex_array_type tile_atlas::wall_quad_S(const Vector3 center, const Vector3 si }}; } -vertex_array_type tile_atlas::wall_quad_W(const Vector3 center, const Vector3 size) +vertex_array_type tile_atlas::wall_quad_S(const Vector3 center, const Vector3 size) { float x = size[0]*.5f, y = size[1]*.5f, z = size[2]; return {{ @@ -1,5 +1,4 @@ #include "tile.hpp" - #include "tile-atlas.hpp" namespace Magnum::Examples { diff --git a/wall-mesh.cpp b/wall-mesh.cpp index 31399aed..c55de472 100644 --- a/wall-mesh.cpp +++ b/wall-mesh.cpp @@ -48,27 +48,11 @@ void wall_mesh::draw(tile_shader& shader, chunk& c) c.foreach_tile([&](tile& x, std::size_t, local_coords pt) { maybe_add_tile(data, textures, pos, x, pt); }); - //_vertex_buffer.setSubData(0, Containers::arrayView(data.data(), pos)); - _vertex_buffer.setData(data, Magnum::GL::BufferUsage::DynamicDraw); + _vertex_buffer.setSubData(0, Containers::arrayView(data.data(), pos)); + //_vertex_buffer.setData(data, Magnum::GL::BufferUsage::DynamicDraw); } const GL::Texture2D* last_texture = nullptr; -#if 0 - if (pos > 0) - { - Magnum::GL::MeshView mesh{_mesh}; - mesh.setCount((int)(pos * quad_index_count)); - mesh.setIndexRange(0); - textures[0]->bind(0); - shader.draw(mesh); - } -#elif 0 - if (pos > 0) - { - textures[0]->bind(0); - shader.draw(_mesh); - } -#else Magnum::GL::MeshView mesh{_mesh}; for (std::size_t i = 0; i < pos; i++) { @@ -76,14 +60,11 @@ void wall_mesh::draw(tile_shader& shader, chunk& c) CORRADE_INTERNAL_ASSERT(tex != nullptr); mesh.setCount(quad_index_count); mesh.setIndexRange((int)(i*quad_index_count), 0, quad_index_count*COUNT - 1); - //mesh.setIndexRange((int)(i*quad_index_count)); - //Debug{} << "draw " << "i:" << i << "count:" << quad_index_count << "range:" << (i*quad_index_count); if (tex != last_texture) tex->bind(0); last_texture = tex; shader.draw(mesh); } -#endif } decltype(wall_mesh::_index_data) wall_mesh::make_index_array() |