From a278b5ce6debd1e5580cb41b3a018a5da9b66263 Mon Sep 17 00:00:00 2001 From: BenCat07 Date: Sat, 22 Jun 2019 15:31:12 +0200 Subject: [PATCH] Add Draw Triangle --- include/glez/draw.hpp | 3 ++- src/draw.cpp | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/glez/draw.hpp b/include/glez/draw.hpp index 08fa88a..7042756 100644 --- a/include/glez/draw.hpp +++ b/include/glez/draw.hpp @@ -15,6 +15,7 @@ namespace glez::draw void line(float x, float y, float dx, float dy, rgba color, float thickness); void rect(float x, float y, float w, float h, rgba color); +void triangle(float x, float y, float x2, float y2, float x3, float y3, rgba color); void rect_outline(float x, float y, float w, float h, rgba color, float thickness); void rect_textured(float x, float y, float w, float h, rgba color, @@ -27,4 +28,4 @@ void string(float x, float y, const std::string &string, font &font, rgba color, float *width, float *height); void outlined_string(float x, float y, const std::string &string, font &font, rgba color, rgba outline, float *width, float *height); -} // namespace glez::draw \ No newline at end of file +} // namespace glez::draw diff --git a/src/draw.cpp b/src/draw.cpp index 8b7a550..6724778 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -18,7 +18,8 @@ namespace indices { static GLuint rectangle[6] = { 0, 1, 2, 2, 3, 0 }; -} +static GLuint triangle[3] = { 0, 1, 2 }; +} // namespace indices void internal_draw_string(float x, float y, const std::string &string, texture_font_t *fnt, glez::rgba color, float *width, @@ -200,6 +201,28 @@ void rect(float x, float y, float w, float h, rgba color) indices::rectangle, 6); } +void triangle(float x, float y, float x2, float y2, float x3, float y3, rgba color) +{ + detail::render::vertex vertices[3]; + + for (auto &vertex : vertices) + { + vertex.mode = static_cast(detail::program::mode::PLAIN); + vertex.color = color; + } + + vertices[0].position = { x, y }; + vertices[1].position = { x2, y2 }; + vertices[2].position = { x3, y3 }; + + if (detail::record::currentRecord) + detail::record::currentRecord->store(vertices, 3, indices::rectangle, + 3); + else + ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 3, + indices::rectangle, 3); +} + void rect_outline(float x, float y, float w, float h, rgba color, float thickness) {