diff --git a/src/raylib.h b/src/raylib.h index 3056a53f..9d0262c4 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1055,6 +1055,7 @@ RLAPI void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segment RLAPI void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle RLAPI void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline RLAPI void DrawTriangleFan(Vector2 *points, int numPoints, Color color); // Draw a triangle fan defined by points +RLAPI void DrawTriangleStrip(Vector2 *points, int pointsCount, Color color); // Draw a triangle strip defined by points RLAPI void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a regular polygon (Vector version) RLAPI void SetShapesTexture(Texture2D texture, Rectangle source); // Define default texture used to draw shapes diff --git a/src/shapes.c b/src/shapes.c index bab8a5a4..190bd4e1 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -1181,6 +1181,8 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, int // Draw a triangle void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color) { + if (rlCheckBufferLimit(4)) rlglDraw(); + #if defined(SUPPORT_QUADS_DRAW_MODE) rlEnableTexture(GetShapesTexture().id); @@ -1214,6 +1216,8 @@ void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color) // Draw a triangle using lines void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color) { + if (rlCheckBufferLimit(6)) rlglDraw(); + rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); rlVertex2f(v1.x, v1.y); @@ -1258,6 +1262,36 @@ void DrawTriangleFan(Vector2 *points, int pointsCount, Color color) } } +// Draw a triangle strip defined by points +// NOTE: Every new point connects with previous two +void DrawTriangleStrip(Vector2 *points, int pointsCount, Color color) +{ + if (pointsCount >= 3) + { + if (rlCheckBufferLimit(pointsCount)) rlglDraw(); + + rlBegin(RL_TRIANGLES); + rlColor4ub(color.r, color.g, color.b, color.a); + + for (int i = 2; i < pointsCount; i++) + { + if ((i%2) == 0) + { + rlVertex2f(points[i].x, points[i].y); + rlVertex2f(points[i - 2].x, points[i - 2].y); + rlVertex2f(points[i - 1].x, points[i - 1].y); + } + else + { + rlVertex2f(points[i].x, points[i].y); + rlVertex2f(points[i - 1].x, points[i - 1].y); + rlVertex2f(points[i - 2].x, points[i - 2].y); + } + } + rlEnd(); + } +} + // Draw a regular polygon of n sides (Vector version) void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color) {