summaryrefslogtreecommitdiffhomepage
path: root/main.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-02-18 09:22:47 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-02-18 09:22:47 +0100
commitd0ff22593b1783bf6c76c1db3922075244a23d11 (patch)
tree36c79db467ed9643039869c5c2771559647d469a /main.cpp
parentdbc638717df7e4639693e06e4a581f57188d2647 (diff)
add projection
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp56
1 files changed, 41 insertions, 15 deletions
diff --git a/main.cpp b/main.cpp
index 07dd6130..84069870 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,4 +1,5 @@
#include "atlas.hpp"
+#include "tile-shader.hpp"
#include <Corrade/Containers/Optional.h>
#include <Corrade/Containers/ArrayViewStl.h>
@@ -8,16 +9,21 @@
#include <Magnum/GL/Buffer.h>
#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/GL/Mesh.h>
+#include <Magnum/GL/Renderer.h>
#include <Magnum/GL/TextureFormat.h>
#include <Magnum/Platform/Sdl2Application.h>
#include <Magnum/Trade/AbstractImporter.h>
#include <Magnum/Trade/ImageData.h>
-#include "tile-shader.hpp"
+#include <Magnum/GlmIntegration/Integration.h>
+#include <glm/glm.hpp>
+#include <glm/ext/matrix_transform.hpp>
+#include <glm/ext/matrix_clip_space.hpp>
namespace Magnum::Examples {
-struct application : Platform::Application {
+struct application final : Platform::Application
+{
explicit application(const Arguments& arguments);
void drawEvent() override;
@@ -30,16 +36,8 @@ struct application : Platform::Application {
tile_shader _shader;
atlas_texture atlas = make_atlas("images/tiles.tga", {8, 4});
- atlas_texture make_atlas(const std::string& file, Vector2i dims)
- {
- if(!tga_importer || !tga_importer->openFile(file))
- std::exit(1);
-
- Containers::Optional<Trade::ImageData2D> image = tga_importer->image2D(0);
- CORRADE_INTERNAL_ASSERT(image);
-
- return atlas_texture{*image, dims};
- }
+ atlas_texture make_atlas(const std::string& file, Vector2i dims);
+ Matrix4x4 make_projection(Vector3 offset);
};
application::application(const Arguments& arguments):
@@ -50,9 +48,10 @@ application::application(const Arguments& arguments):
struct QuadVertex {
Vector3 position;
Vector2 textureCoordinates;
+ // todo gl_FragDepth
};
QuadVertex vertices[4];
- auto positions = atlas.floor_quad({}, {2, 2});
+ auto positions = atlas.floor_quad({}, {48, 48});
auto texcoords = atlas.texcoords_for_id(2);
auto indices = atlas.indices(0);
@@ -66,18 +65,45 @@ application::application(const Arguments& arguments):
}
void application::drawEvent() {
- GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);
+ GL::defaultFramebuffer.clear(GL::FramebufferClear::Color | GL::FramebufferClear::Depth);
+
+ //GL::Renderer::enable(GL::Renderer::Feature::DepthTest);
+ //GL::Renderer::setDepthMask(true);
using namespace Math::Literals;
_shader
- .setColor(0xffffff_rgbf)
+ .set_projection(make_projection({0, 0, 0}))
+ .set_color(0xffffff_rgbf)
.bindTexture(atlas.texture())
.draw(_mesh);
swapBuffers();
}
+atlas_texture application::make_atlas(const std::string& file, Vector2i dims)
+{
+ if(!tga_importer || !tga_importer->openFile(file))
+ std::exit(1);
+
+ Containers::Optional<Trade::ImageData2D> image = tga_importer->image2D(0);
+ CORRADE_INTERNAL_ASSERT(image);
+
+ return atlas_texture{*image, dims};
+}
+
+Matrix4x4 application::make_projection(Vector3 offset)
+{
+ auto m = glm::mat4{1};
+ m = glm::ortho<float>(-256, 256, -256, 256, -512, 512);
+ m = glm::translate(m, { offset[0], -offset[1], offset[2] });
+ m = glm::scale(m, { 1.f, 0.6f, 1.f });
+ m = glm::rotate(m, glm::radians(-45.f), glm::vec3(1.0f, 0.0f, 0.0f));
+ m = glm::rotate(m, glm::radians(0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
+ m = glm::rotate(m, glm::radians(-45.0f), glm::vec3(0.0f, 0.0f, 1.0f));
+ return Matrix4x4{m};
+}
+
} // namespace Magnum::Examples
MAGNUM_APPLICATION_MAIN(Magnum::Examples::application);