not a good idea yet
This commit is contained in:
parent
1a5287bbc2
commit
296d3add7b
4 changed files with 59 additions and 22 deletions
|
@ -24,13 +24,15 @@ layout (location = 0) in vec3 vertices;
|
||||||
layout (location = 1) in vec3 normals;
|
layout (location = 1) in vec3 normals;
|
||||||
layout (location = 2) in vec2 texture_coords;
|
layout (location = 2) in vec2 texture_coords;
|
||||||
|
|
||||||
uniform vec4 pivot = vec4( 0.5, 0.5, 0.0, 1.0 );
|
uniform vec2 pivot = vec2( 0.0, 0.0 );
|
||||||
|
|
||||||
|
vec4 pivot_3d = vec4( pivot , 0.0, 1.0 );
|
||||||
|
|
||||||
out vec2 tex_c;
|
out vec2 tex_c;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
tex_c = texture_coords;
|
tex_c = texture_coords;
|
||||||
gl_Position = vec4(vertices, 1.0) + pivot;
|
gl_Position = vec4(vertices, 1.0) + pivot_3d;
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
|
@ -94,13 +96,21 @@ auto main() -> int {
|
||||||
|
|
||||||
// eine sehr rudimentäre Eingabebehandlung. Bei vorhandenen
|
// eine sehr rudimentäre Eingabebehandlung. Bei vorhandenen
|
||||||
// Eingaben landen diese hier. Wer sich am Design beteiligen
|
// Eingaben landen diese hier. Wer sich am Design beteiligen
|
||||||
// möchte, kann hier einen eleganteren Vorschlag machen
|
// möchte: hier gibt es viel Potential zur Verbesserung ;)
|
||||||
window.set_keyboardcallback(
|
window.set_keyboardcallback(
|
||||||
[&](auto& w, int key, int scancode, int action, int mods) {
|
[&](auto& w, int key, int scancode, int action, int mods) {
|
||||||
if (key == 'Q' || key == 256)
|
if (key == 'Q' || key == 256) // Q oder ESC beenden das Programm
|
||||||
want_close = true;
|
want_close = true;
|
||||||
else if (key == 'A') {
|
else if (key == 'B') { // kleine Spielerei
|
||||||
slider_value += 10;
|
slider_value += 10;
|
||||||
|
} else if (key == 'W') {
|
||||||
|
sprite.pivot.y() += 0.1f;
|
||||||
|
} else if (key == 'S') {
|
||||||
|
sprite.pivot.y() -= 0.1f;
|
||||||
|
} else if (key == 'A') {
|
||||||
|
sprite.pivot.x() -= 0.1f;
|
||||||
|
} else if (key == 'D') {
|
||||||
|
sprite.pivot.x() += 0.1f;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -119,13 +129,16 @@ auto main() -> int {
|
||||||
// werden
|
// werden
|
||||||
ctx.set_viewport(paradiso::Rectangle{
|
ctx.set_viewport(paradiso::Rectangle{
|
||||||
.size =
|
.size =
|
||||||
w.client_size().minimal_extent() // wir wollen das
|
w.client_size().maximal_extent() // wir wollen das
|
||||||
// Seitenverhältnis beibehalten
|
// Seitenverhältnis beibehalten
|
||||||
});
|
});
|
||||||
|
|
||||||
// hier wird das eigentliche löschen des vorherigen Inhalts ausgelöst
|
// hier wird das eigentliche löschen des vorherigen Inhalts ausgelöst
|
||||||
ctx.clear();
|
ctx.clear();
|
||||||
|
|
||||||
|
// wir setzen den pivot der sprite über den shader
|
||||||
|
shader.set_uniform("pivot", sprite.pivot);
|
||||||
|
|
||||||
// Ein `renderer` kann nur mit einer Sprite verwendet werden!
|
// Ein `renderer` kann nur mit einer Sprite verwendet werden!
|
||||||
// Aber ein Shader kann man für mehrere Sprite-Renderer Kombis verwenden
|
// Aber ein Shader kann man für mehrere Sprite-Renderer Kombis verwenden
|
||||||
renderer.draw(sprite, shader);
|
renderer.draw(sprite, shader);
|
||||||
|
|
|
@ -27,11 +27,18 @@
|
||||||
|
|
||||||
namespace paradiso {
|
namespace paradiso {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief position with integral type
|
||||||
|
*/
|
||||||
|
|
||||||
struct Point final {
|
struct Point final {
|
||||||
using value_type = int32_t;
|
using value_type = int32_t;
|
||||||
value_type x{0}, y{0};
|
value_type x{0}, y{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief size with integral type
|
||||||
|
*/
|
||||||
struct Size final {
|
struct Size final {
|
||||||
using value_type = uint32_t;
|
using value_type = uint32_t;
|
||||||
value_type width{0}, height{0};
|
value_type width{0}, height{0};
|
||||||
|
@ -42,11 +49,20 @@ struct Size final {
|
||||||
return {.width = std::min(width, height),
|
return {.width = std::min(width, height),
|
||||||
.height = std::min(width, height)};
|
.height = std::min(width, height)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr Size maximal_extent() const noexcept {
|
||||||
|
return {.width = std::max(width, height),
|
||||||
|
.height = std::max(width, height)};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Rectangle {
|
/**
|
||||||
Point position;
|
* @brief position and size with integral type
|
||||||
Size size;
|
*/
|
||||||
|
|
||||||
|
struct Rectangle final {
|
||||||
|
Point position{.x = 0, .y = 0};
|
||||||
|
Size size{};
|
||||||
|
|
||||||
constexpr bool contains(const Point& p) const noexcept {
|
constexpr bool contains(const Point& p) const noexcept {
|
||||||
return p.x >= position.x && p.x <= position.x + size.width &&
|
return p.x >= position.x && p.x <= position.x + size.width &&
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#define PARADISO_SHADER_HPP
|
#define PARADISO_SHADER_HPP
|
||||||
|
|
||||||
#include <paradiso/globals.hpp>
|
#include <paradiso/globals.hpp>
|
||||||
|
#include <paradiso/matrix.hpp>
|
||||||
|
#include <paradiso/vector.hpp>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
@ -60,6 +62,9 @@ struct Shader final {
|
||||||
set_uniform_at_location(int location,
|
set_uniform_at_location(int location,
|
||||||
int32_t v) const; //!< sets a 32bit signed in a shader
|
int32_t v) const; //!< sets a 32bit signed in a shader
|
||||||
|
|
||||||
|
const Shader&
|
||||||
|
set_uniform_at_location(int location,
|
||||||
|
const Vector2<float>& v) const; //!< sets a 2D float vector
|
||||||
/**
|
/**
|
||||||
* @brief retrieves the position of a uniform
|
* @brief retrieves the position of a uniform
|
||||||
* @param name of the uniform
|
* @param name of the uniform
|
||||||
|
@ -77,7 +82,7 @@ struct Shader final {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sets data of the
|
* sets data of the uniform inside a shader program
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const Shader& set_uniform(std::string const& name, T&& value) const {
|
const Shader& set_uniform(std::string const& name, T&& value) const {
|
||||||
|
@ -87,7 +92,7 @@ struct Shader final {
|
||||||
|
|
||||||
using uniform_t =
|
using uniform_t =
|
||||||
std::variant<bool, int, float,
|
std::variant<bool, int, float,
|
||||||
double /*,vector2f,vector3f,vector4f,matrix4x4f*/>;
|
double ,Vector2<float>/*vector3f,vector4f,matrix4x4f*/>;
|
||||||
using uniform_entry_t = std::tuple<std::string, uniform_t, int>;
|
using uniform_entry_t = std::tuple<std::string, uniform_t, int>;
|
||||||
|
|
||||||
using uniform_cache_t = std::vector<uniform_entry_t>;
|
using uniform_cache_t = std::vector<uniform_entry_t>;
|
||||||
|
|
|
@ -172,16 +172,19 @@ struct Shader::impl {
|
||||||
// glUniformMatrix4fv(location,1,GL_FALSE,m.ptr());
|
// glUniformMatrix4fv(location,1,GL_FALSE,m.ptr());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// void bind(int location,const vector4f& v)
|
void bind(int location, const Vector2<float>& v) const {
|
||||||
// {
|
glUniform2fv(location, 1, v.ptr());
|
||||||
// glUniform4fv(location,1,v.ptr());
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
void bind(int location, const float& v) const { glUniform1f(location, v); }
|
void bind(int location, const float& v) const { glUniform1f(location, v); }
|
||||||
|
|
||||||
void bind(int location, const uint32_t& i) const { glUniform1ui(location, i); }
|
void bind(int location, const uint32_t& i) const {
|
||||||
|
glUniform1ui(location, i);
|
||||||
|
}
|
||||||
|
|
||||||
void bind(int location, const int32_t& i) const { glUniform1i(location, i); }
|
void bind(int location, const int32_t& i) const {
|
||||||
|
glUniform1i(location, i);
|
||||||
|
}
|
||||||
|
|
||||||
// void bind(int location,const texture& v)
|
// void bind(int location,const texture& v)
|
||||||
// {
|
// {
|
||||||
|
@ -211,11 +214,11 @@ const Shader& Shader::set_uniform_at_location(int location, int32_t v) const {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shader &Shader::set_uniform_at_location(int location, vector4f const &v)
|
const Shader &Shader::set_uniform_at_location(int location, Vector2<float> const &v) const
|
||||||
// {
|
{
|
||||||
// impl_->bind(location, v);
|
impl_->bind(location, v);
|
||||||
// return *this;
|
return *this;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Shader &Shader::set_uniform_at_location(int location, matrix4x4f const &v)
|
// Shader &Shader::set_uniform_at_location(int location, matrix4x4f const &v)
|
||||||
// {
|
// {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue