summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--main/app.cpp9
-rw-r--r--main/app.hpp3
-rw-r--r--main/camera.cpp39
-rw-r--r--main/main.cpp45
-rw-r--r--src/tile-atlas.cpp2
-rw-r--r--src/wireframe-mesh.cpp33
-rw-r--r--src/wireframe-mesh.hpp37
7 files changed, 84 insertions, 84 deletions
diff --git a/main/app.cpp b/main/app.cpp
index 66857860..89d680de 100644
--- a/main/app.cpp
+++ b/main/app.cpp
@@ -7,7 +7,8 @@ app::app(const Arguments& arguments):
arguments,
Configuration{}
.setTitle("Test")
- .setSize({1024, 768}, dpi_policy::Physical),
+ .setSize({1024, 768}, dpi_policy::Physical)
+ .setWindowFlags(Configuration::WindowFlag::Resizable),
GLConfiguration{}
.setSampleCount(4)
.setFlags(GLConfiguration::Flag::GpuValidation)
@@ -17,12 +18,6 @@ app::app(const Arguments& arguments):
timeline.start();
}
-void app::update_window_scale()
-{
- auto sz = windowSize();
- _shader.set_scale({ (float)sz[0], (float)sz[1] });
-}
-
void app::update(float dt)
{
do_camera(dt);
diff --git a/main/app.hpp b/main/app.hpp
index 06ad882e..c1b45af9 100644
--- a/main/app.hpp
+++ b/main/app.hpp
@@ -28,7 +28,8 @@ struct app final : Platform::Application
void keyReleaseEvent(KeyEvent& event) override;
void do_key(KeyEvent::Key k, KeyEvent::Modifiers m, bool pressed, bool repeated);
void draw_chunk(chunk& c);
- void update_window_scale();
+ void update_window_scale(Vector2i window_size);
+ void viewportEvent(ViewportEvent& event) override;
enum class key : int {
camera_up, camera_left, camera_right, camera_down, camera_reset,
diff --git a/main/camera.cpp b/main/camera.cpp
new file mode 100644
index 00000000..c9fb0391
--- /dev/null
+++ b/main/camera.cpp
@@ -0,0 +1,39 @@
+#include "app.hpp"
+
+namespace Magnum::Examples {
+
+void app::do_camera(float dt)
+{
+ constexpr float pixels_per_second = 512;
+ if (keys[key::camera_up])
+ camera_offset += Vector2(0, 1) * dt * pixels_per_second;
+ else if (keys[key::camera_down])
+ camera_offset += Vector2(0, -1) * dt * pixels_per_second;
+ if (keys[key::camera_left])
+ camera_offset += Vector2(1, 0) * dt * pixels_per_second;
+ else if (keys[key::camera_right])
+ camera_offset += Vector2(-1, 0) * dt * pixels_per_second;
+
+ _shader.set_camera_offset(camera_offset);
+
+ if (keys[key::camera_reset])
+ reset_camera_offset();
+}
+
+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 = {};
+}
+
+void app::update_window_scale(Vector2i sz)
+{
+ _shader.set_scale(Vector2{sz});
+}
+
+void app::viewportEvent(Platform::Sdl2Application::ViewportEvent& event)
+{
+ update_window_scale(event.windowSize());
+}
+
+} // namespace Magnum::Examples
diff --git a/main/main.cpp b/main/main.cpp
index 34a7ae4a..2545865f 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -32,7 +32,7 @@ void app::drawEvent() {
GL::Renderer::setDepthFunction(GL::Renderer::DepthFunction::Never);
#endif
- update_window_scale();
+ update_window_scale(windowSize());
{
float dt = timeline.previousFrameDuration();
update(dt);
@@ -51,44 +51,23 @@ void app::draw_chunk(chunk& c)
_wall_mesh.draw(_shader, c);
}
-void app::do_camera(float dt)
-{
- constexpr float pixels_per_second = 512;
- if (keys[key::camera_up])
- camera_offset += Vector2(0, 1) * dt * pixels_per_second;
- else if (keys[key::camera_down])
- camera_offset += Vector2(0, -1) * dt * pixels_per_second;
- if (keys[key::camera_left])
- camera_offset += Vector2(1, 0) * dt * pixels_per_second;
- else if (keys[key::camera_right])
- camera_offset += Vector2(-1, 0) * dt * pixels_per_second;
-
- _shader.set_camera_offset(camera_offset);
-
- if (keys[key::camera_reset])
- reset_camera_offset();
-}
-
-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 = {};
-}
-
-
-
} // namespace Magnum::Examples
MAGNUM_APPLICATION_MAIN(Magnum::Examples::app)
#ifdef _MSC_VER
-# include <cstdlib>
-# ifdef __clang__
-# pragma clang diagnostic ignored "-Wmissing-prototypes"
-# pragma clang diagnostic ignored "-Wmain"
-# endif
+#include <cstdlib> // for __arg{c,v}
+#ifdef __clang__
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wmain"
+#endif
+extern "C" int __stdcall WinMain(void*, void*, void*, int);
-extern "C" int __stdcall WinMain(void*, void*, void*, int /* nCmdShow */) {
+extern "C" int __stdcall WinMain(void*, void*, void*, int)
+{
return main(__argc, __argv);
}
+#ifdef __clang__
+# pragma clang diagnostic pop
+#endif
#endif
diff --git a/src/tile-atlas.cpp b/src/tile-atlas.cpp
index 08bc2296..917c60bc 100644
--- a/src/tile-atlas.cpp
+++ b/src/tile-atlas.cpp
@@ -14,7 +14,7 @@ tile_atlas::tile_atlas(Containers::StringView name, const ImageView2D& image, Ve
CORRADE_INTERNAL_ASSERT(dims_[0] > 0 && dims_[1] > 0);
CORRADE_INTERNAL_ASSERT(size_ % dims_ == Vector2ui{});
CORRADE_INTERNAL_ASSERT(dims_.product() < 256);
- tex_.setWrapping(GL::SamplerWrapping::ClampToBorder)
+ tex_.setWrapping(GL::SamplerWrapping::ClampToEdge)
.setMagnificationFilter(GL::SamplerFilter::Nearest)
.setMinificationFilter(GL::SamplerFilter::Linear)
.setMaxAnisotropy(0)
diff --git a/src/wireframe-mesh.cpp b/src/wireframe-mesh.cpp
index 236f27ed..8d5d259f 100644
--- a/src/wireframe-mesh.cpp
+++ b/src/wireframe-mesh.cpp
@@ -7,15 +7,16 @@
#include <Magnum/PixelFormat.h>
#include <Magnum/Trade/ImageData.h>
-namespace Magnum::Examples::wireframe_traits {
+namespace Magnum::Examples::wireframe
+{
-GL::RectangleTexture wireframe_traits::null::make_constant_texture()
+GL::RectangleTexture wireframe::null::make_constant_texture()
{
Trade::ImageData2D img{PixelFormat::RGBA8UI, {1, 1}, // NOLINT(misc-const-correctness)
Containers::Array<char>{Corrade::DirectInit, 4, (char)(unsigned char)255}};
GL::RectangleTexture tex;
- tex.setWrapping(GL::SamplerWrapping::Repeat)
+ tex.setWrapping(GL::SamplerWrapping::ClampToEdge)
.setMagnificationFilter(GL::SamplerFilter::Nearest)
.setMinificationFilter(GL::SamplerFilter::Nearest)
.setMaxAnisotropy(0)
@@ -24,7 +25,7 @@ GL::RectangleTexture wireframe_traits::null::make_constant_texture()
return tex;
}
-quad::vertex_array quad::make_vertex_positions_array() const
+quad::vertex_array quad::make_vertex_array() const
{
constexpr auto X = TILE_SIZE[0], Y = TILE_SIZE[1];
constexpr float Z = 0;
@@ -38,34 +39,28 @@ quad::vertex_array quad::make_vertex_positions_array() const
quad::quad(Vector3 center, Vector2 size) : center(center), size(size) {}
-} // namespace Magnum::Examples::wireframe_traits
+} // namespace Magnum::Examples::wireframe
namespace Magnum::Examples {
-using wireframe_traits::traits;
-
-template <traits T> wireframe_mesh<T>::wireframe_mesh()
+template <wireframe::traits T> wireframe_mesh<T>::wireframe_mesh()
{
_mesh.setCount((int)T::num_vertices)
.addVertexBuffer(_texcoords_buffer, 0, tile_shader::TextureCoordinates{})
- .addVertexBuffer(_positions_buffer, 0, tile_shader::Position{});
- if constexpr(T::num_indices > 0)
- _mesh.setIndexBuffer(_index_buffer, 0, GL::MeshIndexType::UnsignedShort);
- CORRADE_INTERNAL_ASSERT(T::num_indices > 0 == _mesh.isIndexed());
-};
+ .addVertexBuffer(_vertex_buffer, 0, tile_shader::Position{});
+ CORRADE_INTERNAL_ASSERT(!_mesh.isIndexed());
+}
-template <traits T> void wireframe_mesh<T>::draw(tile_shader& shader, T x)
+template <wireframe::traits T> void wireframe_mesh<T>::draw(tile_shader& shader, T x)
{
GL::Renderer::setLineWidth(2);
- _positions_buffer.setData(x.make_vertex_positions_array(), GL::BufferUsage::DynamicDraw);
- if constexpr(T::num_indices > 0)
- _index_buffer.setData(x.make_index_array(), GL::BufferUsage::DynamicDraw);
+ _vertex_buffer.setData(x.make_vertex_array(), GL::BufferUsage::DynamicDraw);
_texture.bind(0);
shader.draw(_mesh);
}
-template struct wireframe_mesh<wireframe_traits::null>;
-template struct wireframe_mesh<wireframe_traits::quad>;
+template struct wireframe_mesh<wireframe::null>;
+template struct wireframe_mesh<wireframe::quad>;
} // namespace Magnum::Examples
diff --git a/src/wireframe-mesh.hpp b/src/wireframe-mesh.hpp
index 28619e90..855e673a 100644
--- a/src/wireframe-mesh.hpp
+++ b/src/wireframe-mesh.hpp
@@ -14,67 +14,58 @@ namespace Magnum::Examples {
struct tile_shader;
-namespace wireframe_traits {
+namespace wireframe
+{
template<typename T>
concept traits = requires (const T& x) {
{T::num_vertices} -> std::convertible_to<std::size_t>;
- {T::num_indices} -> std::convertible_to<std::size_t>;
{x.primitive} -> std::convertible_to<GL::MeshPrimitive>;
- {x.make_vertex_positions_array() } -> std::same_as<std::array<Vector3, T::num_vertices>>;
- {x.make_index_array() } -> std::same_as<std::array<UnsignedShort, T::num_indices>>;
+ {x.make_vertex_array() } -> std::same_as<std::array<Vector3, T::num_vertices>>;
};
struct null final
{
static constexpr auto primitive = GL::MeshPrimitive::Triangles;
- static constexpr std::size_t num_vertices = 0, num_indices = 0;
+ static constexpr std::size_t num_vertices = 0;
static GL::RectangleTexture make_constant_texture();
- static std::array<Vector3, 0> make_vertex_positions_array() { return {}; }
- static std::array<UnsignedShort, 0> make_index_array() { return {}; }
+ static std::array<Vector3, 0> make_vertex_array() { return {}; }
};
struct quad final
{
- quad(Vector3 center, Vector2 size = {TILE_SIZE[0], TILE_SIZE[1]});
+ quad(Vector3 center, Vector2 size);
constexpr quad() = default;
static constexpr std::size_t num_vertices = 4;
- static constexpr std::size_t num_indices = 0;
static constexpr GL::MeshPrimitive primitive = GL::MeshPrimitive::LineLoop;
using vertex_array = std::array<Vector3, num_vertices>;
- using index_array = std::array<UnsignedShort, num_indices>;
-
- vertex_array make_vertex_positions_array() const;
- static index_array make_index_array() { return {}; }
+ vertex_array make_vertex_array() const;
private:
Vector3 center = {};
Vector2 size = { TILE_SIZE[0], TILE_SIZE[1] };
};
-} // namespace wireframe_traits
-
+} // namespace wireframe
-template<wireframe_traits::traits T>
+template<wireframe::traits T>
struct wireframe_mesh final
{
wireframe_mesh();
void draw(tile_shader& shader, T traits);
private:
- GL::Buffer _positions_buffer{},
- _texcoords_buffer{std::array<Vector2, T::num_vertices>{}},
- _index_buffer{T::num_indices == 0 ? GL::Buffer{NoCreate} : GL::Buffer{}};
- GL::RectangleTexture _texture = wireframe_traits::null::make_constant_texture();
+ GL::Buffer _vertex_buffer{}, _texcoords_buffer{std::array<Vector2, T::num_vertices>{}};
+ GL::RectangleTexture _texture = wireframe::null::make_constant_texture();
GL::Mesh _mesh;
};
-extern template struct wireframe_mesh<wireframe_traits::null>;
-extern template struct wireframe_mesh<wireframe_traits::quad>;
+extern template struct wireframe_mesh<wireframe::null>;
+extern template struct wireframe_mesh<wireframe::quad>;
-using wireframe_quad_mesh = wireframe_mesh<wireframe_traits::quad>;
+using wireframe_quad_mesh = wireframe_mesh<wireframe::quad>;
} // namespace Magnum::Examples