From 6a524b46cb9c74c8d1b710c23bbc62bdafd54bb2 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 19 Oct 2021 07:05:31 +0200 Subject: Use uint8_t for color instead of float --- depends/mgl | 2 +- include/mglpp/graphics/Color.hpp | 11 +++++++---- src/graphics/Rectangle.cpp | 2 +- tests/main.cpp | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/depends/mgl b/depends/mgl index 4a96d4a..3bdf82e 160000 --- a/depends/mgl +++ b/depends/mgl @@ -1 +1 @@ -Subproject commit 4a96d4a354fbde7fd614075c060aea78a3411b42 +Subproject commit 3bdf82eec2c915e91ae487e29d72639f9efcad67 diff --git a/include/mglpp/graphics/Color.hpp b/include/mglpp/graphics/Color.hpp index d1c1745..0d0ac15 100644 --- a/include/mglpp/graphics/Color.hpp +++ b/include/mglpp/graphics/Color.hpp @@ -1,12 +1,15 @@ #ifndef MGLPP_COLOR_HPP #define MGLPP_COLOR_HPP +#include + namespace mgl { struct Color { - float r = 1.0f; - float g = 1.0f; - float b = 1.0f; - float a = 1.0f; + Color(uint8_t r = 255, uint8_t g = 255, uint8_t b = 255, uint8_t a = 255) : r(r), g(g), b(b), a(a) { + + } + + uint8_t r, g, b, a; }; } diff --git a/src/graphics/Rectangle.cpp b/src/graphics/Rectangle.cpp index 61a45f4..17060c7 100644 --- a/src/graphics/Rectangle.cpp +++ b/src/graphics/Rectangle.cpp @@ -6,7 +6,7 @@ extern "C" { namespace mgl { Rectangle::Rectangle(vec2f position, vec2f size) { - rectangle.color = { 1.0f, 1.0f, 1.0f, 1.0f }; + rectangle.color = { 255, 255, 255, 255 }; rectangle.position = { position.x, position.y }; rectangle.size = { size.x, size.y }; } diff --git a/tests/main.cpp b/tests/main.cpp index bddfc3f..3595717 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -12,11 +12,11 @@ struct Delegate : public mgl::Window::Delegate { void draw() override { mgl::Rectangle rect(window->get_cursor_position().to_vec2f(), { 100.0f, 500.0f }); - rect.set_color({1.0f, 0.0f, 0.0f, 1.0f}); + rect.set_color({255, 0, 0, 255}); window->draw(rect); mgl::Sprite sprite(*texture, { 100.0f - 10.0f, 0.0f }); - sprite.set_color({1.0f, 1.0f, 1.0f, 0.5f}); + sprite.set_color({255, 255, 255, 128}); window->draw(sprite); mgl::Text text("hello world!\nGood bye world!", { 0.0f, 0.0f }, *font); -- cgit v1.2.3