summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-06-11 23:21:04 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-06-11 23:21:04 +0200
commitda042f527536ba2ba82e5aa823e4fd132afebe1e (patch)
tree8ee1a9ecbc915b2b6a29882ca32272c91ee91190
parent565570f905be11faa17c1c95c7ac207c641c395d (diff)
a
-rw-r--r--atlas.cpp8
-rw-r--r--atlas.hpp2
-rw-r--r--main.cpp46
-rw-r--r--shaders/tile-shader.vert6
-rw-r--r--tile-shader.cpp5
-rw-r--r--tile-shader.hpp6
6 files changed, 17 insertions, 56 deletions
diff --git a/atlas.cpp b/atlas.cpp
index d40cec11..5904dc19 100644
--- a/atlas.cpp
+++ b/atlas.cpp
@@ -50,7 +50,7 @@ vertex_array_type atlas_texture::floor_quad(Vector3 center, Vector2 size)
}};
}
-vertex_array_type atlas_texture::wall_quad_N(Vector3 center, Vector3 size)
+vertex_array_type atlas_texture::wall_quad_W(Vector3 center, Vector3 size)
{
float x = size[0]*.5f, y = size[1]*.5f, z = size[2];
return {{
@@ -61,7 +61,7 @@ vertex_array_type atlas_texture::wall_quad_N(Vector3 center, Vector3 size)
}};
}
-vertex_array_type atlas_texture::wall_quad_W(Vector3 center, Vector3 size)
+vertex_array_type atlas_texture::wall_quad_S(Vector3 center, Vector3 size)
{
float x = size[0]*.5f, y = size[1]*.5f, z = size[2];
return {{
@@ -72,7 +72,7 @@ vertex_array_type atlas_texture::wall_quad_W(Vector3 center, Vector3 size)
}};
}
-vertex_array_type atlas_texture::wall_quad_S(Vector3 center, Vector3 size)
+vertex_array_type atlas_texture::wall_quad_E(Vector3 center, Vector3 size)
{
float x = size[0]*.5f, y = size[1]*.5f, z = size[2];
return {{
@@ -83,7 +83,7 @@ vertex_array_type atlas_texture::wall_quad_S(Vector3 center, Vector3 size)
}};
}
-vertex_array_type atlas_texture::wall_quad_E(Vector3 center, Vector3 size)
+vertex_array_type atlas_texture::wall_quad_N(Vector3 center, Vector3 size)
{
float x = size[0]*.5f, y = size[1]*.5f, z = size[2];
return {{
diff --git a/atlas.hpp b/atlas.hpp
index 671679bb..e54a5efd 100644
--- a/atlas.hpp
+++ b/atlas.hpp
@@ -12,10 +12,10 @@ struct atlas_texture final
atlas_texture(const ImageView2D& img, Vector2i dims);
std::array<Vector2, 4> texcoords_for_id(int id) const;
static vertex_array_type floor_quad(Vector3 center, Vector2 size);
- static vertex_array_type wall_quad_W(Vector3 center, Vector3 size);
static vertex_array_type wall_quad_S(Vector3 center, Vector3 size);
static vertex_array_type wall_quad_E(Vector3 center, Vector3 size);
static vertex_array_type wall_quad_N(Vector3 center, Vector3 size);
+ static vertex_array_type wall_quad_W(Vector3 center, Vector3 size);
static std::array<UnsignedShort, 6> indices(int N);
GL::Texture2D& texture() { return tex_; }
constexpr int size() const { return dims_.product(); }
diff --git a/main.cpp b/main.cpp
index 9d3bf91d..19abaf85 100644
--- a/main.cpp
+++ b/main.cpp
@@ -58,48 +58,13 @@ struct application final : Platform::Application
std::bitset<(std::size_t)key::MAX> keys{0ul};
float get_dt();
-
- static glm::mat<4, 4, double> make_projection(Vector2i window_size, Vector3 offset);
- static glm::mat<4, 4, double> make_view(Vector3 offset);
- static float projection_size_ratio();
- Matrix4x4 make_projection(Vector3 offset) const;
static const Vector3 TILE_SIZE;
};
-const Vector3 application::TILE_SIZE =
- [] { auto x = 50 * application::projection_size_ratio(); return Vector3{x, x, 50}; }();
+const Vector3 application::TILE_SIZE = { 50, 50, 50 };
using namespace Math::Literals;
-float application::projection_size_ratio()
-{
- auto m = make_projection({1, 1}, {});
- glm::vec<4, double> pos = glm::vec<4, double>{.5, 0, 0, 1} * m;
- return (float)(pos[0] / pos[3]);
-}
-
-glm::mat<4, 4, double> application::make_view(Vector3 offset) {
- using vec3 = glm::vec<3, double>;
- using mat4 = glm::mat<4, 4, double>;
- mat4 m{1};
- m = glm::scale(glm::mat<4, 4, double>{1}, { 1., .6, 1. });
- m = glm::translate(m, { (double)offset[0], (double)-offset[1], (double)offset[2] });
- m = glm::rotate(m, glm::radians(-std::atan(1./std::sqrt(2))), vec3(0, 1, 0));
- m = glm::rotate(m, glm::radians(-45.), vec3(0, 0, 1));
- return m;
-}
-
-glm::mat<4, 4, double> application::make_projection(Vector2i window_size, Vector3 offset)
-{
- double x = window_size[0]*.5, y = window_size[1]*.5, w = 2*std::max(window_size[0], window_size[1]);
- return glm::mat4(glm::ortho(-x, x, -y, y, -w, w) * make_view(offset));
-}
-
-Matrix4x4 application::make_projection(Vector3 offset) const
-{
- return Magnum::Matrix4x4{glm::mat4{make_projection(windowSize(), offset)}};
-}
-
application::application(const Arguments& arguments):
Platform::Application{
arguments,
@@ -107,7 +72,7 @@ application::application(const Arguments& arguments):
.setTitle("Test")
.setSize({1024, 768}, dpi_policy::Physical),
GLConfiguration{}
- .setSampleCount(16)
+ //.setSampleCount(16)
}
{
struct QuadVertex {
@@ -151,9 +116,9 @@ application::application(const Arguments& arguments):
{
atlas_texture::vertex_array_type walls[] = {
atlas2->wall_quad_W({}, Vector3(X, Y, Z)),
- atlas2->wall_quad_S({}, Vector3(X, Y, Z)),
atlas2->wall_quad_N({}, Vector3(X, Y, Z)),
atlas2->wall_quad_E({}, Vector3(X, Y, Z)),
+ atlas2->wall_quad_S({}, Vector3(X, Y, Z)),
};
int k = 0;
@@ -193,10 +158,9 @@ void application::drawEvent() {
}
{
- auto projection = make_projection(camera_offset);
//auto ratio = projection_size_ratio();
- float y_scale = 1.2f/windowSize()[1];
- _shader.set_projection(projection, y_scale);
+ auto sz = windowSize();
+ _shader.set_projection({(float)sz[0], (float)sz[1]}, 1);
}
#if 1
diff --git a/shaders/tile-shader.vert b/shaders/tile-shader.vert
index 10b17f38..a7e9e660 100644
--- a/shaders/tile-shader.vert
+++ b/shaders/tile-shader.vert
@@ -2,7 +2,7 @@ precision highp float;
layout(location = 0) in vec4 position;
layout(location = 1) in vec2 textureCoordinates;
-layout(location = 0) uniform mat4 projection;
+layout(location = 0) uniform vec2 projection;
layout(location = 1) uniform float y_scale;
out vec2 interpolatedTextureCoordinates;
@@ -11,6 +11,8 @@ out float interpolated_frag_depth;
void main() {
interpolatedTextureCoordinates = textureCoordinates;
- gl_Position = projection * vec4(position.xy, 0, position.w) + vec4(0, position.z * y_scale, 0, 0);
+ float cx = 2/projection.x, cy = 2/projection.y;
+ float x = position.x, y = position.y, z = position.z*y_scale;
+ gl_Position = vec4((x-y)*cx, (x+y+z*2)*cx, 0, 1);
interpolated_frag_depth = -position.z;
}
diff --git a/tile-shader.cpp b/tile-shader.cpp
index 3d42ef80..dd66955b 100644
--- a/tile-shader.cpp
+++ b/tile-shader.cpp
@@ -25,9 +25,6 @@ tile_shader::tile_shader()
CORRADE_INTERNAL_ASSERT_OUTPUT(link());
- _projection_uniform = uniformLocation("projection");
- _y_scale_uniform = uniformLocation("y_scale");
-
setUniform(uniformLocation("textureData"), TextureUnit);
}
@@ -37,7 +34,7 @@ tile_shader& tile_shader::bindTexture(GL::Texture2D& texture)
return *this;
}
-tile_shader& tile_shader::set_projection(const Matrix4& mat, float y_scale)
+tile_shader& tile_shader::set_projection(const Vector2& mat, float y_scale)
{
setUniform(_projection_uniform, mat);
setUniform(_y_scale_uniform, y_scale);
diff --git a/tile-shader.hpp b/tile-shader.hpp
index 3a2b6d37..147444a3 100644
--- a/tile-shader.hpp
+++ b/tile-shader.hpp
@@ -13,15 +13,13 @@ struct tile_shader : GL::AbstractShaderProgram
typedef GL::Attribute<1, Vector2> TextureCoordinates;
explicit tile_shader();
-
- tile_shader& set_projection(const Math::Matrix4<float>& mat, float y_scale);
-
+ tile_shader& set_projection(const Vector2& mat, float y_scale);
tile_shader& bindTexture(GL::Texture2D& texture);
private:
enum: Int { TextureUnit = 0 };
- Int _projection_uniform, _y_scale_uniform;
+ enum { _projection_uniform = 0, _y_scale_uniform = 1 };
};
} // namespace Magnum::Examples