From ebda20ff9cfb3c9be105d39838daa5336019623f Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sun, 13 Jun 2021 14:14:25 +0300 Subject: [PATCH] Support drawing multi-color triangles in gfx::painter --- libs/gfx/include/psemek/gfx/painter.hpp | 1 + libs/gfx/source/painter.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libs/gfx/include/psemek/gfx/painter.hpp b/libs/gfx/include/psemek/gfx/painter.hpp index e8d352eb..0068c5b8 100644 --- a/libs/gfx/include/psemek/gfx/painter.hpp +++ b/libs/gfx/include/psemek/gfx/painter.hpp @@ -53,6 +53,7 @@ namespace psemek::gfx // 2D void triangle(geom::point const & p0, geom::point const & p1, geom::point const & p2, color const & c); + void triangle(geom::point const & p0, geom::point const & p1, geom::point const & p2, color const & c0, color const & c1, color const & c2); void rect(geom::box const & box, color const & c); void circle(geom::point const & center, float radius, color const & c, int quality = 24); void line(geom::point const & p0, geom::point const & p1, float width, color const & c, bool smooth = true); diff --git a/libs/gfx/source/painter.cpp b/libs/gfx/source/painter.cpp index 3229ad7f..e307fd94 100644 --- a/libs/gfx/source/painter.cpp +++ b/libs/gfx/source/painter.cpp @@ -184,12 +184,17 @@ namespace psemek::gfx painter::~painter() = default; void painter::triangle(geom::point const & p0, geom::point const & p1, geom::point const & p2, color const & c) + { + triangle(p0, p1, p2, c, c, c); + } + + void painter::triangle(geom::point const & p0, geom::point const & p1, geom::point const & p2, color const & c0, color const & c1, color const & c2) { std::uint32_t const base = impl().vertices.size(); - impl().vertices.push_back({{p0[0], p0[1], 0.f}, c}); - impl().vertices.push_back({{p1[0], p1[1], 0.f}, c}); - impl().vertices.push_back({{p2[0], p2[1], 0.f}, c}); + impl().vertices.push_back({{p0[0], p0[1], 0.f}, c0}); + impl().vertices.push_back({{p1[0], p1[1], 0.f}, c1}); + impl().vertices.push_back({{p2[0], p2[1], 0.f}, c2}); impl().indices.push_back(base + 0); impl().indices.push_back(base + 1);