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); +} diff --git a/src/raylib.h b/src/raylib.h index 11010f14..128711c9 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1325,7 +1325,6 @@ RLAPI void DrawTextureQuad(Texture2D texture, Vector2 tiling, Vector2 offset, Re RLAPI void DrawTextureTiled(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint); // Draw part of a texture (defined by a rectangle) with rotation and scale tiled into dest. RLAPI void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint); // Draw a part of a texture defined by a rectangle with 'pro' parameters RLAPI void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint); // Draws a texture (or part of it) that stretches or shrinks nicely -RLAPI void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 *texcoords, int pointCount, Color tint); // Draw a textured polygon // Color/pixel related functions RLAPI Color Fade(Color color, float alpha); // Get color with alpha applied, alpha goes from 0.0f to 1.0f diff --git a/src/rtextures.c b/src/rtextures.c index 343daa18..5440ed7c 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -3906,37 +3906,6 @@ void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, } } -// Draw textured polygon, defined by vertex and texturecoordinates -// 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); -} - // Get color with alpha applied, alpha goes from 0.0f to 1.0f Color Fade(Color color, float alpha) {