From 84a2a8857229a696852bb97938e1ec2f7b1df892 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 10 Nov 2022 10:05:11 +0100 Subject: WARNING: REMOVED: `DrawTexturePoly()` Function moved to `examples/textures/textures_polygon.c`, so users can learn from the implementation and create custom variants as required. --- examples/textures/textures_polygon.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'examples') diff --git a/examples/textures/textures_polygon.c b/examples/textures/textures_polygon.c index 357862c3..287029f7 100644 --- a/examples/textures/textures_polygon.c +++ b/examples/textures/textures_polygon.c @@ -14,10 +14,15 @@ ********************************************************************************************/ #include "raylib.h" + +#include "rlgl.h" // Required for: Vertex definition #include "raymath.h" #define MAX_POINTS 11 // 10 points and back to the start +// Draw textured polygon, defined by vertex and texture coordinates +void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 *texcoords, int pointCount, Color tint); + //------------------------------------------------------------------------------------ // Program main entry point //------------------------------------------------------------------------------------ @@ -102,3 +107,34 @@ int main(void) return 0; } + +// Draw textured polygon, defined by vertex and texture coordinates +// NOTE: Polygon center must have straight line path to all points +// without crossing perimeter, points must be in anticlockwise order +void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 *texcoords, int pointCount, Color tint) +{ + rlSetTexture(texture.id); + + // Texturing is only supported on RL_QUADS + rlBegin(RL_QUADS); + + rlColor4ub(tint.r, tint.g, tint.b, tint.a); + + for (int i = 0; i < pointCount - 1; i++) + { + rlTexCoord2f(0.5f, 0.5f); + rlVertex2f(center.x, center.y); + + rlTexCoord2f(texcoords[i].x, texcoords[i].y); + rlVertex2f(points[i].x + center.x, points[i].y + center.y); + + rlTexCoord2f(texcoords[i + 1].x, texcoords[i + 1].y); + rlVertex2f(points[i + 1].x + center.x, points[i + 1].y + center.y); + + rlTexCoord2f(texcoords[i + 1].x, texcoords[i + 1].y); + rlVertex2f(points[i + 1].x + center.x, points[i + 1].y + center.y); + } + rlEnd(); + + rlSetTexture(0); +} -- cgit v1.2.3