From 9893ad823a230936eba469178ddd0a0a4e07a6e8 Mon Sep 17 00:00:00 2001 From: codifies Date: Thu, 25 Mar 2021 12:34:26 +0000 Subject: [PATCH] moved DrawTexturePoly to textures function and example NB function name changed to fit with other DrawTextureXXX functions (no "d" ) --- examples/Makefile | 6 +-- .../textures_poly.c} | 6 +-- src/raylib.h | 2 +- src/shapes.c | 42 ------------------- src/textures.c | 42 +++++++++++++++++++ 5 files changed, 49 insertions(+), 49 deletions(-) rename examples/{shapes/shapes_textured_polygon.c => textures/textures_poly.c} (93%) diff --git a/examples/Makefile b/examples/Makefile index cabbc99a6..c8fc3fb26 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -416,8 +416,7 @@ SHAPES = \ shapes/shapes_easings_rectangle_array \ shapes/shapes_draw_ring \ shapes/shapes_draw_circle_sector \ - shapes/shapes_draw_rectangle_rounded \ - shapes/shapes_textured_polygon + shapes/shapes_draw_rectangle_rounded TEXTURES = \ textures/textures_logo_raylib \ @@ -438,7 +437,8 @@ TEXTURES = \ textures/textures_sprite_explosion \ textures/textures_bunnymark \ textures/textures_blend_modes \ - textures/textures_draw_tiled + textures/textures_draw_tiled \ + textures/textures_poly TEXT = \ text/text_raylib_fonts \ diff --git a/examples/shapes/shapes_textured_polygon.c b/examples/textures/textures_poly.c similarity index 93% rename from examples/shapes/shapes_textured_polygon.c rename to examples/textures/textures_poly.c index 7b9c47140..bfb8cdc50 100644 --- a/examples/shapes/shapes_textured_polygon.c +++ b/examples/textures/textures_poly.c @@ -47,9 +47,9 @@ int main(void) pnts[i].y = (tPnts[i].y - 0.5) * 256.0; } - InitWindow(screenWidth, screenHeight, "raylib [shapes] example - Textured Polygon"); + InitWindow(screenWidth, screenHeight, "raylib [textures] example - Textured Polygon"); - Texture tex = LoadTexture("../textures/resources/cat.png"); + Texture tex = LoadTexture("resources/cat.png"); SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -77,7 +77,7 @@ int main(void) DrawText("Textured Polygon", 20, 20, 20, DARKGRAY); - DrawTexturedPoly(tex, screenWidth/2, screenHeight/2, + DrawTexturePoly(tex, screenWidth/2, screenHeight/2, dPnts, tPnts, numPnts, WHITE); EndDrawing(); diff --git a/src/raylib.h b/src/raylib.h index 99fce14e9..fcf820a96 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1147,7 +1147,6 @@ RLAPI void DrawTriangleFan(Vector2 *points, int pointsCount, Color color); 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 DrawPolyLines(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a polygon outline of n sides -RLAPI void DrawTexturedPoly(Texture t, float x, float y, Vector2 *points, Vector2 *tPnts, int numPoints, Color colour); // Draw a textured polygon // Basic shapes collision detection functions RLAPI bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles @@ -1261,6 +1260,7 @@ 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(Texture t, float x, float y, Vector2 *points, Vector2 *tPnts, int numPoints, Color colour); // 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/shapes.c b/src/shapes.c index e8974662f..b615f78af 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -1419,48 +1419,6 @@ void DrawPolyLines(Vector2 center, int sides, float radius, float rotation, Colo rlPopMatrix(); } - -// 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 DrawTexturedPoly(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(); - -} - //---------------------------------------------------------------------------------- // Module Functions Definition - Collision Detection functions //---------------------------------------------------------------------------------- diff --git a/src/textures.c b/src/textures.c index 875f736c3..61e6f30ba 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) {