diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2022-06-11 23:35:30 +0200 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-06-11 23:35:30 +0200 |
| commit | 440808a5ad98bdcd4024a2e0f552d83dfa21c5d2 (patch) | |
| tree | 193622e8249ad9cd02c79a66c4cd04be3a0d48b0 | |
| parent | da042f527536ba2ba82e5aa823e4fd132afebe1e (diff) | |
a
| -rw-r--r-- | main.cpp | 4 | ||||
| -rw-r--r-- | shaders/tile-shader.vert | 9 | ||||
| -rw-r--r-- | tile-shader.cpp | 7 | ||||
| -rw-r--r-- | tile-shader.hpp | 7 |
4 files changed, 12 insertions, 15 deletions
@@ -51,7 +51,7 @@ struct application final : Platform::Application loader.tile_atlas("../share/game/images/metal1.tga", {2, 2}); //loader.tile_atlas("../share/game/images/floor1.tga", {4, 4}); std::shared_ptr<atlas_texture> atlas2 = - loader.tile_atlas("../share/game/images/metal2.tga", {4, 4}); + loader.tile_atlas("../share/game/images/metal2.tga", {2, 2}); std::uint64_t time_ticks = 0, time_freq = SDL_GetPerformanceFrequency(); Vector3 camera_offset; @@ -160,7 +160,7 @@ void application::drawEvent() { { //auto ratio = projection_size_ratio(); auto sz = windowSize(); - _shader.set_projection({(float)sz[0], (float)sz[1]}, 1); + _shader.set_scale({ (float)sz[0], (float)sz[1] }); } #if 1 diff --git a/shaders/tile-shader.vert b/shaders/tile-shader.vert index a7e9e660..03c1f08a 100644 --- a/shaders/tile-shader.vert +++ b/shaders/tile-shader.vert @@ -2,8 +2,7 @@ precision highp float; layout(location = 0) in vec4 position; layout(location = 1) in vec2 textureCoordinates; -layout(location = 0) uniform vec2 projection; -layout(location = 1) uniform float y_scale; +layout(location = 0) uniform vec2 scale; out vec2 interpolatedTextureCoordinates; out float interpolated_frag_depth; @@ -11,8 +10,8 @@ out float interpolated_frag_depth; void main() { interpolatedTextureCoordinates = textureCoordinates; - 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); + float cx = 2/scale.x, cy = 2/scale.y; + float x = position.x, y = position.y, z = position.z; + gl_Position = vec4((x-y)*cx, (x+y+z*2)*cx*0.75, 0, 1); interpolated_frag_depth = -position.z; } diff --git a/tile-shader.cpp b/tile-shader.cpp index dd66955b..ba1e135f 100644 --- a/tile-shader.cpp +++ b/tile-shader.cpp @@ -25,7 +25,7 @@ tile_shader::tile_shader() CORRADE_INTERNAL_ASSERT_OUTPUT(link()); - setUniform(uniformLocation("textureData"), TextureUnit); + setUniform(TextureUnit, TextureUnit); } tile_shader& tile_shader::bindTexture(GL::Texture2D& texture) @@ -34,10 +34,9 @@ tile_shader& tile_shader::bindTexture(GL::Texture2D& texture) return *this; } -tile_shader& tile_shader::set_projection(const Vector2& mat, float y_scale) +tile_shader& tile_shader::set_scale(const Vector2& scale) { - setUniform(_projection_uniform, mat); - setUniform(_y_scale_uniform, y_scale); + setUniform(ProjectionUniform, scale); return *this; } diff --git a/tile-shader.hpp b/tile-shader.hpp index 147444a3..f412c49d 100644 --- a/tile-shader.hpp +++ b/tile-shader.hpp @@ -13,13 +13,12 @@ struct tile_shader : GL::AbstractShaderProgram typedef GL::Attribute<1, Vector2> TextureCoordinates; explicit tile_shader(); - tile_shader& set_projection(const Vector2& mat, float y_scale); + tile_shader& set_scale(const Vector2& scale); tile_shader& bindTexture(GL::Texture2D& texture); private: - enum: Int { TextureUnit = 0 }; - - enum { _projection_uniform = 0, _y_scale_uniform = 1 }; + enum { TextureUnit = 0 }; + enum { ProjectionUniform = 0, }; }; } // namespace Magnum::Examples |
