Define the behavior of a negative width or height passed to SDL_RenderFillRect()

The software renderer now matches the 3D renderer behavior by rendering a reversed rectangle (extending width or height in the opposite direction) when width or height is negative. It also now renders no rectangle if the width and height are 0.

Fixes https://github.com/libsdl-org/SDL/issues/13400
This commit is contained in:
Sam Lantinga
2025-09-07 12:08:38 -07:00
parent a5d790124c
commit cd6b68a9fb
2 changed files with 22 additions and 7 deletions

View File

@@ -124,16 +124,23 @@ static int SDLCALL render_testPrimitives(void *arg)
rect.y = 0.0f;
rect.w = 40.0f;
rect.h = 80.0f;
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 13, 73, 200, SDL_ALPHA_OPAQUE))
CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
/* Draw a rectangle. */
/* Draw a rectangle with negative width and height. */
rect.x = 10.0f + 60.0f;
rect.y = 10.0f + 40.0f;
rect.w = -60.0f;
rect.h = -40.0f;
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 200, 0, 100, SDL_ALPHA_OPAQUE))
CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
/* Draw a rectangle with zero width and height. */
rect.x = 10.0f;
rect.y = 10.0f;
rect.w = 60.0f;
rect.h = 40.0f;
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 200, 0, 100, SDL_ALPHA_OPAQUE))
rect.w = 0.0f;
rect.h = 0.0f;
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 255, 0, 0, SDL_ALPHA_OPAQUE))
CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
/* Draw some points like so: