diff --git a/libs/gfx/include/psemek/gfx/painter.hpp b/libs/gfx/include/psemek/gfx/painter.hpp index a8b8cb83..3b0406d7 100644 --- a/libs/gfx/include/psemek/gfx/painter.hpp +++ b/libs/gfx/include/psemek/gfx/painter.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include @@ -20,7 +20,8 @@ namespace psemek::gfx ~painter(); // 2D - void quad(geom::point const & center, float width, color const & c); + void triangle(geom::point const & p0, geom::point const & p1, geom::point const & p2, color const & c); + void rect(geom::box const & box, color const & c); void circle(geom::point const & center, float radius, color const & c); 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 c1b88f65..87019d5f 100644 --- a/libs/gfx/source/painter.cpp +++ b/libs/gfx/source/painter.cpp @@ -62,15 +62,27 @@ namespace psemek::gfx painter::~painter() = default; - void painter::quad(geom::point const & p, float width, color const & c) + void painter::triangle(geom::point const & p0, geom::point const & p1, geom::point const & p2, color const & c) { std::uint32_t const base = impl().vertices.size(); - float const r = width / 2.f; - impl().vertices.push_back({{p[0] - r, p[1] - r, 0.f}, c}); - impl().vertices.push_back({{p[0] + r, p[1] - r, 0.f}, c}); - impl().vertices.push_back({{p[0] - r, p[1] + r, 0.f}, c}); - impl().vertices.push_back({{p[0] + r, p[1] + r, 0.f}, c}); + 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().indices.push_back(base + 0); + impl().indices.push_back(base + 1); + impl().indices.push_back(base + 2); + } + + void painter::rect(geom::box const & box, color const & c) + { + std::uint32_t const base = impl().vertices.size(); + + impl().vertices.push_back({{box[0].min, box[1].min, 0.f}, c}); + impl().vertices.push_back({{box[0].max, box[1].min, 0.f}, c}); + impl().vertices.push_back({{box[0].min, box[1].max, 0.f}, c}); + impl().vertices.push_back({{box[0].max, box[1].max, 0.f}, c}); impl().indices.push_back(base + 0); impl().indices.push_back(base + 1);