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 1746 - Transparency set with SDL_ColorKey fails to transfer over to SDL_Textures with SDL_CreateTextureFromSurface()
Summary: Transparency set with SDL_ColorKey fails to transfer over to SDL_Textures wit...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.0
Hardware: x86_64 Android (All)
: P2 minor
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-07 23:32 UTC by sn0w75
Modified: 2019-01-16 11:56 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sn0w75 2013-03-07 23:32:16 UTC
Hi, I've been developing with SDL2 for a couple years now; it's a beautiful library for making portable 2D games with hardware acceleration :D

I've tested this code in Linux 64-bit, Windows 32-bit, and Android (Nexus 7); Android appears to be the only platform affected by this bug.

On Linux and Windows, the code causes the SDL_Texture to use RGB value 255,0,255 as the transparent color. But on Android, it fails to do this, for some reason.

My code does not change at all whatsoever for the Android version. There is a small '#ifdef __ANDROID__' snippet that changes the root location for the data folder, but that's the only OS-specific code I have in my project.

The code is the following:
fontSurface=loadImage(fontName.c_str());

Uint32 bgColor = SDL_MapRGB( fontSurface->format, 0xFF, 0, 0xFF );
SDL_SetColorKey(fontSurface,SDL_TRUE,bgColor);
printf("SDL_SetColorKey failed: %s\n", SDL_GetError());
	
fontTexture=SDL_CreateTextureFromSurface(renderer,fontSurface);

.......

SDL_RenderCopy(renderer,fontTexture,&chars[unicode],&dst);

I've attached screenshots of the result on each platform (For Windows I'm running it in Wine for the screenshot)
Linux: http://i.imgur.com/ZI36bQc.png
Windows (Wine): http://i.imgur.com/avw0ZnL.png
Android: http://i.imgur.com/QIeT4T4.png


Please let me know if there is any other information I can provide.
Much thanks!
-sn0w75
Comment 1 sn0w75 2013-03-07 23:35:29 UTC
Sorry, there's a small typo in the code I wrote, was trying to throw out all the error-checking code for simplicity:

printf("SDL_SetColorKey failed: %s\n", SDL_GetError());

^^^Throw this line out (or put it in a proper try/catch set) and you're good to go ;)
Comment 2 Sam Lantinga 2013-03-24 11:57:41 UTC
Can you a attach a simple test that I can run to reproduce this?

Thanks!
Comment 3 Sylvain 2017-09-05 10:39:39 UTC
I believe this is the same bug 2979
when creating a texture, the surface can be converting internally to match one of the renderer available formats.
Comment 4 Sam Lantinga 2017-09-10 02:01:31 UTC
I think you're right, I believe this is fixed.

Thanks!
Comment 5 Sylvain 2019-01-16 11:56:39 UTC
This commit tells it fixes it: 
https://hg.libsdl.org/SDL/rev/1d49dc7b5ce9
( and also https://hg.libsdl.org/SDL/rev/4eb8ac58642c )