summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/raylib.h10
-rw-r--r--src/textures.c53
2 files changed, 27 insertions, 36 deletions
diff --git a/src/raylib.h b/src/raylib.h
index 472e1751..2c6f40b2 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -1266,12 +1266,12 @@ RLAPI void SetTextureWrap(Texture2D texture, int wrap);
RLAPI void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D
RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2
RLAPI void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters
-RLAPI void DrawTextureRec(Texture2D texture, Rectangle source, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle
+RLAPI void DrawTextureRec(Texture2D texture, Rectangle source, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle
RLAPI void DrawTextureQuad(Texture2D texture, Vector2 tiling, Vector2 offset, Rectangle quad, Color tint); // Draw texture quad with tiling and offset parameters
-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(Texture t, float x, float y, Vector2 *points, Vector2 *tPnts, int numPoints, Color colour); // Draw a textured polygon
+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 pointsCount, Color tint); // Draw a textured polygon
// Color/pixel related functions
RLAPI Color Fade(Color color, float alpha); // Returns color with alpha applied, alpha goes from 0.0f to 1.0f
diff --git a/src/textures.c b/src/textures.c
index 0e61edc2..ec97757e 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -3510,48 +3510,39 @@ void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest,
}
}
-// t texture to use
-// x,y position to draw the poly (centre)
-// points points of the poly (relative to 0,0)
-// tPnts uv coordinates
-// numPoints number of points in the poly
-// colour the tint of the poly
-//
-// NB centre (0,0) must have straight line path to all points
-// without crossing perimeter, points must be in anticlockwise
-// order
-void DrawTexturePoly(Texture t, float x, float y,
- Vector2 *points, Vector2 *tPnts,
- int numPoints, Color colour)
+// 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 pointsCount, Color tint)
{
- rlEnableTexture(t.id);
+ rlCheckRenderBatchLimit((pointsCount - 1)*4);
+
+ rlSetTexture(texture.id);
- // for some reason texturing doesn't work on trianglesso make a
- // degenerate QUAD, DrawTriangleFan does this too why ?
- rlCheckRenderBatchLimit((numPoints-1)*4);
+ // Texturing is only supported on QUADs
rlBegin(RL_QUADS);
- rlColor4ub(colour.r, colour.g, colour.b, colour.a);
- for (int i = 0; i < numPoints-1; i++)
- {
- rlTexCoord2f(0.5, 0.5);
- rlVertex2f(x, y);
+ rlColor4ub(tint.r, tint.g, tint.b, tint.a);
- rlTexCoord2f(tPnts[i].x, tPnts[i].y);
- rlVertex2f(points[i].x + x, points[i].y + y);
+ for (int i = 0; i < pointsCount - 1; i++)
+ {
+ rlTexCoord2f(0.5f, 0.5f);
+ rlVertex2f(center.x, center.y);
- rlTexCoord2f(tPnts[i + 1].x, tPnts[i + 1].y);
- rlVertex2f(points[i + 1].x + x, points[i + 1].y + y);
+ rlTexCoord2f(texcoords[i].x, texcoords[i].y);
+ rlVertex2f(points[i].x + center.x, points[i].y + center.y);
- rlTexCoord2f(tPnts[i + 1].x, tPnts[i + 1].y);
- rlVertex2f(points[i + 1].x + x, points[i + 1].y + 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();
- rlDisableTexture();
+ rlSetTexture(0);
}
-
// Returns color with alpha applied, alpha goes from 0.0f to 1.0f
Color Fade(Color color, float alpha)
{