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 3243 - SDL_SetRenderDrawColor() behaves wrong with RGBA=0
Summary: SDL_SetRenderDrawColor() behaves wrong with RGBA=0
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: render (show other bugs)
Version: 2.0.4
Hardware: x86_64 Linux
: P2 minor
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-19 23:25 UTC by steffhip
Modified: 2017-08-12 19:59 UTC (History)
1 user (show)

See Also:


Attachments
Patch that fixes the initialization of the current color in the GL and GL ES renderers. (839 bytes, patch)
2016-06-12 11:00 UTC, Simon Hug
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description steffhip 2016-01-19 23:25:48 UTC
When using the SDL_SetRenderDrawColor() function and all 3 colors and the alpha channel is set to zero, following SDL_RenderDrawLine and SDL_RenderDrawRect functions will render in white instead of the expected black.

A workaround for this, is setting any of the 4 values to a different value.

However a SDL_RenderClear() after SDL_SetRenderDrawColor(r,0,0,0,0) works as expected, and clears with black.

Following example code demonstrates the issue:


// compile with: cc colorbug.c `pkg-config --libs --cflags sdl2` -o colorbug
#include <SDL.h>

int main(){
    SDL_Window* win;
    SDL_Renderer* ren;
    SDL_Event eve;
    SDL_Rect rec = {.x = 25, .y = 25, .w = 50, .h = 50};

    if (SDL_Init(SDL_INIT_VIDEO) < 0) return -1;
    if (SDL_CreateWindowAndRenderer(100, 100, SDL_WINDOW_RESIZABLE, &win, &ren)) return -1;
    SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_NONE);
        
    for(;;){
        for (;SDL_PollEvent(&eve);)
            if (SDL_QUIT == eve.type) return 0;
        // setting background color (works as expected)
        SDL_SetRenderDrawColor(ren, 0x80, 0x80, 0x80, 0x00); 
        SDL_RenderClear(ren);
        // setting color for rectangle (should be black, but is white)
        SDL_SetRenderDrawColor(ren, 0x00, 0x00, 0x00, 0x00); 
        SDL_RenderDrawLine(ren, 25, 25, 75, 75);
        SDL_RenderDrawRect(ren, &rec);
        SDL_RenderPresent(ren);
        SDL_Delay(20);
    }
}
Comment 1 Simon Hug 2016-06-12 11:00:14 UTC
Created attachment 2491 [details]
Patch that fixes the initialization of the current color in the GL and GL ES renderers.

This issue can be reproduced with the opengl and opengles renderers.

The bug is in the GL_ResetState and GLES_ResetState functions which get called after a new GL context is created. These functions set the cached current color to transparent black, but the GL specification says the initial color is opaque white.

The attached patch changes the values to 0xffffffff to reflect the initial state of the current color. Should the ResetState functions get called anywhere else in the future, this probably has to call the GL functions itself to ensure that the colors match.
Comment 2 Sam Lantinga 2017-08-12 19:59:36 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/54f46b251fe1