Add Draw Triangle

This commit is contained in:
BenCat07 2019-06-22 15:31:12 +02:00
parent c3000f17c4
commit a278b5ce6d
2 changed files with 26 additions and 2 deletions

View File

@ -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
} // namespace glez::draw

View File

@ -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<int>(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)
{