| Summary: | SDL_SetRenderDrawColor() behaves wrong with RGBA=0 | ||
|---|---|---|---|
| Product: | SDL | Reporter: | steffhip |
| Component: | render | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | minor | ||
| Priority: | P2 | CC: | chli.hug |
| Version: | 2.0.4 | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
| Attachments: | Patch that fixes the initialization of the current color in the GL and GL ES renderers. | ||
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.
Fixed, thanks! https://hg.libsdl.org/SDL/rev/54f46b251fe1 |
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); } }