summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--main/app.cpp33
-rw-r--r--main/app.hpp2
-rw-r--r--main/keyboard.cpp43
-rw-r--r--main/main.cpp65
-rw-r--r--src/wireframe-mesh.cpp3
-rw-r--r--src/wireframe-mesh.hpp2
6 files changed, 83 insertions, 65 deletions
diff --git a/main/app.cpp b/main/app.cpp
new file mode 100644
index 00000000..66857860
--- /dev/null
+++ b/main/app.cpp
@@ -0,0 +1,33 @@
+#include "app.hpp"
+
+namespace Magnum::Examples {
+
+app::app(const Arguments& arguments):
+ Platform::Application{
+ arguments,
+ Configuration{}
+ .setTitle("Test")
+ .setSize({1024, 768}, dpi_policy::Physical),
+ GLConfiguration{}
+ .setSampleCount(4)
+ .setFlags(GLConfiguration::Flag::GpuValidation)
+ }
+{
+ reset_camera_offset();
+ 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);
+ if (keys[key::quit])
+ Platform::Sdl2Application::exit(0);
+}
+
+} // namespace Magnum::Examples
diff --git a/main/app.hpp b/main/app.hpp
index 4cea0a32..06ad882e 100644
--- a/main/app.hpp
+++ b/main/app.hpp
@@ -5,6 +5,7 @@
#include "src/loader.hpp"
#include "floor-mesh.hpp"
#include "wall-mesh.hpp"
+#include "wireframe-mesh.hpp"
#include "compat/enum-bitset.hpp"
#include <Magnum/Timeline.h>
#include <Magnum/Platform/Sdl2Application.h>
@@ -44,6 +45,7 @@ struct app final : Platform::Application
chunk _chunk = make_test_chunk();
floor_mesh _floor_mesh;
wall_mesh _wall_mesh;
+ wireframe_quad_mesh _wireframe_quad;
Vector2 camera_offset;
enum_bitset<key> keys;
diff --git a/main/keyboard.cpp b/main/keyboard.cpp
new file mode 100644
index 00000000..14daa19c
--- /dev/null
+++ b/main/keyboard.cpp
@@ -0,0 +1,43 @@
+#include "app.hpp"
+namespace Magnum::Examples {
+
+void app::do_key(KeyEvent::Key k, KeyEvent::Modifiers m, bool pressed, bool repeated)
+{
+ //using Mods = KeyEvent::Modifiers;
+
+ (void)m;
+ (void)repeated;
+
+ const key x = progn(switch (k) {
+ using enum KeyEvent::Key;
+ using enum key;
+
+ case W: return camera_up;
+ case A: return camera_left;
+ case S: return camera_down;
+ case D: return camera_right;
+ case Home: return camera_reset;
+ case Esc: return quit;
+ default: return MAX;
+ });
+
+ if (x != key::MAX)
+ keys[x] = pressed;
+}
+
+app::~app()
+{
+ loader_::destroy();
+}
+
+void app::keyPressEvent(Platform::Sdl2Application::KeyEvent& event)
+{
+ do_key(event.key(), event.modifiers(), true, event.isRepeated());
+}
+
+void app::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event)
+{
+ do_key(event.key(), event.modifiers(), false, false);
+}
+
+} // namespace Magnum::Examples
diff --git a/main/main.cpp b/main/main.cpp
index 5a555c97..34a7ae4a 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -5,21 +5,6 @@
namespace Magnum::Examples {
-app::app(const Arguments& arguments):
- Platform::Application{
- arguments,
- Configuration{}
- .setTitle("Test")
- .setSize({1024, 768}, dpi_policy::Physical),
- GLConfiguration{}
- .setSampleCount(4)
- .setFlags(GLConfiguration::Flag::GpuValidation)
- }
-{
- reset_camera_offset();
- timeline.start();
-}
-
chunk app::make_test_chunk()
{
constexpr auto N = TILE_MAX_DIM;
@@ -60,12 +45,6 @@ void app::drawEvent() {
timeline.nextFrame();
}
-void app::update_window_scale()
-{
- auto sz = windowSize();
- _shader.set_scale({ (float)sz[0], (float)sz[1] });
-}
-
void app::draw_chunk(chunk& c)
{
_floor_mesh.draw(_shader, c);
@@ -96,51 +75,7 @@ void app::reset_camera_offset()
//camera_offset = {};
}
-void app::update(float dt)
-{
- do_camera(dt);
- if (keys[key::quit])
- Platform::Sdl2Application::exit(0);
-}
-void app::do_key(KeyEvent::Key k, KeyEvent::Modifiers m, bool pressed, bool repeated)
-{
- //using Mods = KeyEvent::Modifiers;
-
- (void)m;
- (void)repeated;
-
- const key x = progn(switch (k) {
- using enum KeyEvent::Key;
- using enum key;
-
- case W: return camera_up;
- case A: return camera_left;
- case S: return camera_down;
- case D: return camera_right;
- case Home: return camera_reset;
- case Esc: return quit;
- default: return MAX;
- });
-
- if (x != key::MAX)
- keys[x] = pressed;
-}
-
-app::~app()
-{
- loader_::destroy();
-}
-
-void app::keyPressEvent(Platform::Sdl2Application::KeyEvent& event)
-{
- do_key(event.key(), event.modifiers(), true, event.isRepeated());
-}
-
-void app::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event)
-{
- do_key(event.key(), event.modifiers(), false, false);
-}
} // namespace Magnum::Examples
diff --git a/src/wireframe-mesh.cpp b/src/wireframe-mesh.cpp
index 5b60cead..236f27ed 100644
--- a/src/wireframe-mesh.cpp
+++ b/src/wireframe-mesh.cpp
@@ -2,6 +2,7 @@
#include "shaders/tile-shader.hpp"
#include <Corrade/Containers/Array.h>
#include <Magnum/ImageView.h>
+#include <Magnum/GL/Renderer.h>
#include <Magnum/GL/TextureFormat.h>
#include <Magnum/PixelFormat.h>
#include <Magnum/Trade/ImageData.h>
@@ -55,9 +56,11 @@ template <traits T> wireframe_mesh<T>::wireframe_mesh()
template <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);
+ _texture.bind(0);
shader.draw(_mesh);
}
diff --git a/src/wireframe-mesh.hpp b/src/wireframe-mesh.hpp
index c31ee1d0..28619e90 100644
--- a/src/wireframe-mesh.hpp
+++ b/src/wireframe-mesh.hpp
@@ -75,4 +75,6 @@ private:
extern template struct wireframe_mesh<wireframe_traits::null>;
extern template struct wireframe_mesh<wireframe_traits::quad>;
+using wireframe_quad_mesh = wireframe_mesh<wireframe_traits::quad>;
+
} // namespace Magnum::Examples