summaryrefslogtreecommitdiffhomepage
path: root/src/textures.c
diff options
context:
space:
mode:
authorchriscamacho <[email protected]>2021-03-25 13:22:10 +0000
committerGitHub <[email protected]>2021-03-25 14:22:10 +0100
commit9569d6a802a2230c92503456d544a5470a59d5cf (patch)
tree2ab9ac314c03b689b9dd8dced8c14d3569119afb /src/textures.c
parentdd5935048539486b0672d8cf112f3df806352dea (diff)
downloadraylib-9569d6a802a2230c92503456d544a5470a59d5cf.tar.gz
raylib-9569d6a802a2230c92503456d544a5470a59d5cf.zip
Add DrawTexturedPoly and example (#1677)
* adds DrawTexturedPoly with example * the actual example ... ahem * moved DrawTexturePoly to textures function and example NB function name changed to fit with other DrawTextureXXX functions (no "d" ) Co-authored-by: codifies <[email protected]>
Diffstat (limited to 'src/textures.c')
-rw-r--r--src/textures.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/textures.c b/src/textures.c
index 875f736c..61e6f30b 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -3510,6 +3510,48 @@ 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)
+{
+ rlEnableTexture(t.id);
+
+ // for some reason texturing doesn't work on trianglesso make a
+ // degenerate QUAD, DrawTriangleFan does this too why ?
+ rlCheckRenderBatchLimit((numPoints-1)*4);
+ 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);
+
+ rlTexCoord2f(tPnts[i].x, tPnts[i].y);
+ rlVertex2f(points[i].x + x, points[i].y + y);
+
+ rlTexCoord2f(tPnts[i + 1].x, tPnts[i + 1].y);
+ rlVertex2f(points[i + 1].x + x, points[i + 1].y + y);
+
+ rlTexCoord2f(tPnts[i + 1].x, tPnts[i + 1].y);
+ rlVertex2f(points[i + 1].x + x, points[i + 1].y + y);
+ }
+ rlEnd();
+ rlDisableTexture();
+
+}
+
+
// Returns color with alpha applied, alpha goes from 0.0f to 1.0f
Color Fade(Color color, float alpha)
{