guisan icon indicating copy to clipboard operation
guisan copied to clipboard

SDL2 - Guisans rendertarget combined with SDL_Colorkey

Open Johanneslueke opened this issue 7 years ago • 3 comments

At the moment i am experimenting with guisan within my little project. Everything is done sofar with SDL_Texture except Guisan which as you best know utilize SDL_Surfaces instead SDL_Texture for rendering itself if SDL2 is chosen as "Graphics Engine"

Per sé this is absolutly fine. When guisan has finished rendering stuff on its SDL_Surface target I simply convert this Surface into an SDL_Texture or to be more precise I Update an pre-existing SDL_Texture and then Render this specific SDL_Texture. This works perfectly.

Till here everything is fine. I can interact with my GUI and the rest of my application. Then i thought at some point why not use an colour key (0xff00ff) to make the target of guisan transparent except for the parts it is drawing his stuff.

So i started calling:

SDL_FillRect(guisanTarget,NULL,*0xff00ff*); To Fill my Target with the colour key i am about to hide away, with this call: SDL_SetColorKey(guisanTarget,SDL_TRUE,SDL_MapRGB(guisanTarget->format,0xff,0x00,0xff));

And here is where my problem occurs... if i try to set my colour key the result will be a black screen. No visible GUI to interact with. If I DO NOT set the colour key via SDL_SetColorKey then i get my GUI with the background colour i filled my Target via SDL_FillRect.

I have no clue why... If anyone has an idea what the reason for this behaviour is please let me know i would appreciate it a lot.

Johanneslueke avatar Jan 23 '17 17:01 Johanneslueke

From what I have noticed so far, it seems to me that this is more an SDL2 problem than an issue with Guisan itself. The problem happens when converting a Surface using a colorkey to a Texture. It would be interesting to see how it goes with the latest version of SDL2 (2.0.5).

gbaudic avatar Aug 28 '17 21:08 gbaudic

Pull requests welcome on improvements + changes. I'm still around, just not actively invested in guisan at the moment. I have a PCEngine emulator I originally ported GuiChan to SDL2 for, but never got around to using it.

kallisti5 avatar Sep 02 '17 19:09 kallisti5

This issue is now 2 years old, so I am mainly writing this for future reference. Using the latest versions of the SDL libraries, I still run into this problem: filling an SDL_Surface with the color which was used to set the colorkey produces the color instead of transparency.
The workaround I found is to instead "clear" the surface with a transparent color, for example SDL_MapRGBA(0xff, 0, 0xff, 0) for a "transparent magenta" (Invisible Pink Unicorn anyone?).

gbaudic avatar Feb 01 '19 19:02 gbaudic