From 61b2725ef174e4cec734e29bce4f69d6fcd2a813 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 24 Aug 2024 13:54:14 +0200 Subject: Vertices: fix alpha blending when window background is transparent, add uniform for color, add position for vertices draw --- depends/mgl | 2 +- include/mglpp/graphics/Shader.hpp | 2 ++ include/mglpp/window/Window.hpp | 2 +- src/graphics/Shader.cpp | 4 ++++ src/window/Window.cpp | 4 ++-- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/depends/mgl b/depends/mgl index 8731a00..6af3b55 160000 --- a/depends/mgl +++ b/depends/mgl @@ -1 +1 @@ -Subproject commit 8731a00681a2cf99965203849bd7ba8f6c09df9a +Subproject commit 6af3b55b9a11cf85e850eba0fddcf531e2002c7f diff --git a/include/mglpp/graphics/Shader.hpp b/include/mglpp/graphics/Shader.hpp index 2d1336d..e2bb1ad 100644 --- a/include/mglpp/graphics/Shader.hpp +++ b/include/mglpp/graphics/Shader.hpp @@ -2,6 +2,7 @@ #define MGLPP_SHADER_HPP #include "../system/vec.hpp" +#include "../graphics/Color.hpp" extern "C" { #include @@ -24,6 +25,7 @@ namespace mgl { bool load_from_file(const char *filepath, Type type); bool set_uniform(const char *name, float value); bool set_uniform(const char *name, vec2f value); + bool set_uniform(const char *name, Color color); bool is_valid() const; diff --git a/include/mglpp/window/Window.hpp b/include/mglpp/window/Window.hpp index f25e63e..d355db7 100644 --- a/include/mglpp/window/Window.hpp +++ b/include/mglpp/window/Window.hpp @@ -66,7 +66,7 @@ namespace mgl { void clear(Color color = Color(0, 0, 0, 255)); void draw(Drawable &drawable, Shader *shader = nullptr); - void draw(const Vertex *vertices, size_t vertex_count, PrimitiveType primitive_type, Shader *shader = nullptr); + void draw(const Vertex *vertices, size_t vertex_count, PrimitiveType primitive_type, mgl::vec2f position, Shader *shader = nullptr); void display(); void set_visible(bool visible); diff --git a/src/graphics/Shader.cpp b/src/graphics/Shader.cpp index 2bdc9b2..111f39d 100644 --- a/src/graphics/Shader.cpp +++ b/src/graphics/Shader.cpp @@ -34,6 +34,10 @@ namespace mgl { return mgl_shader_program_set_uniform_vec2f(&shader_program, name, { value.x, value.y }) == 0; } + bool Shader::set_uniform(const char *name, Color color) { + return mgl_shader_program_set_uniform_color(&shader_program, name, { color.r, color.g, color.b, color.a }) == 0; + } + bool Shader::is_valid() const { return shader_program.id != 0; } diff --git a/src/window/Window.cpp b/src/window/Window.cpp index 0e80456..8cfc28e 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -53,13 +53,13 @@ namespace mgl { Shader::use(nullptr); } - void Window::draw(const Vertex *vertices, size_t vertex_count, PrimitiveType primitive_type, Shader *shader) { + void Window::draw(const Vertex *vertices, size_t vertex_count, PrimitiveType primitive_type, mgl::vec2f position, Shader *shader) { // TODO: Make the opengl context active for this thread and window, if it already isn't if(shader) Shader::use(shader); mgl_context *context = mgl_get_context(); - mgl_vertices_draw(context, (const mgl_vertex*)vertices, vertex_count, (mgl_primitive_type)primitive_type, { 0.0f, 0.0f }); + mgl_vertices_draw(context, (const mgl_vertex*)vertices, vertex_count, (mgl_primitive_type)primitive_type, { position.x, position.y }); if(shader) Shader::use(nullptr); -- cgit v1.2.3