From 885f83aff4c806dcebfb16e96a329db1d6ca672d Mon Sep 17 00:00:00 2001 From: Jeffery Myers Date: Tue, 29 Dec 2020 08:20:18 -0800 Subject: [PATCH] Update ImageDrawRectangle to be faster too. --- src/textures.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/textures.c b/src/textures.c index cc5755214..9291ebbe0 100644 --- a/src/textures.c +++ b/src/textures.c @@ -2547,9 +2547,19 @@ void ImageDrawRectangleRec(Image *dst, Rectangle rec, Color color) // Security check to avoid program crash if ((dst->data == NULL) || (dst->width == 0) || (dst->height == 0)) return; - Image imRec = GenImageColor((int)rec.width, (int)rec.height, color); - ImageDraw(dst, imRec, (Rectangle){ 0, 0, rec.width, rec.height }, rec, WHITE); - UnloadImage(imRec); + int sy = (int)rec.y; + int ey = sy + (int)rec.height; + + int sx = (int)rec.x; + int ex = sx + (int)rec.width; + + for (int y = sy; y < ey; y++) + { + for (int x = sx; x < ex; x++) + { + ImageDrawPixel(dst, x, y, color); + } + } } // Draw rectangle lines within an image