We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3704

Summary: SDL_RenderDrawRect smaller than SDL_RenderFillRect
Product: SDL Reporter: ibmicroapple
Component: renderAssignee: Ryan C. Gordon <icculus>
Status: ASSIGNED --- QA Contact: Sam Lantinga <slouken>
Severity: minor    
Priority: P2    
Version: 2.0.5   
Hardware: x86_64   
OS: Windows 7   
Attachments: Screenshot of the problem

Description ibmicroapple 2017-07-17 13:40:47 UTC
Created attachment 2800 [details]
Screenshot of the problem

Good day,

Whilst creating a framework based on SDL2.0.5 i came across a weird behaviour when using SDL_RenderDrawRect and SDL_RenderFillRect.

procedure:

SDL_Rect dstrect = {0, 0, x, y};
CALL SDL_RenderFillRect(renderer, &dstrect);
CALL SDL_RenderDrawRect(renderer, &dstrect);

result:

The DrawRect is supposed to draw a rectangle on top of the filled rectangle to create borders around it. However it does not cover the edges on the right and bottom side. One pixel is missing in y direction and 1 in x direction. This can be "fixed" by changing the SDL_RenderDrawRect function:

int
SDL_RenderDrawRect(SDL_Renderer * renderer, const SDL_Rect * rect)
{
    SDL_Rect full_rect;
    SDL_Point points[5];

    CHECK_RENDERER_MAGIC(renderer, -1);

    /* If 'rect' == NULL, then outline the whole surface */
    if (!rect) {
        SDL_RenderGetViewport(renderer, &full_rect);
        full_rect.x = 0;
        full_rect.y = 0;
        rect = &full_rect;
    }

    points[0].x = rect->x;
    points[0].y = rect->y;
    points[1].x = rect->x+rect->w; //<< change made here
    points[1].y = rect->y;
    points[2].x = rect->x+rect->w; //<< change made here
    points[2].y = rect->y+rect->h; //<< change made here
    points[3].x = rect->x;
    points[3].y = rect->y+rect->h; //<< change made here
    points[4].x = rect->x;
    points[4].y = rect->y;
    return SDL_RenderDrawLines(renderer, points, 5);
}

I do not know if this behaviour is intended it seems odd to me.

Thank you for reviewing this report, I sincerely hope it is not a problem just occuring on my side (because of a mistake i made)  :-)
Comment 1 Sam Lantinga 2017-08-11 18:06:21 UTC
Ryan, can you sort this out once and for all? It seems to be driver dependent, and I'm not sure of the correct way to get the behavior we want for all drivers.