Skip to main content
GameDev.net gamedev.net
🔒 Locked

SDL - Transparent icons?

Started by BauerGL Sep 6, 2007 at 8:09 AM 7 replies 4.4k views
Original Post
BauerGL
BauerGL
Is there any way to get transparent icons in SDL? I've tried loading a .bmp and then setting a color key, but that only turns the color key into black. So is there an easy way to have an icon with transparency with SDL? I've thought of using SDL_Image but that would mean using another library just for displaying the icon. I don't need half-alpha pixels, I just need to set fully transparent/opaque.
BauerGL
BauerGL
I'm doing this:

SDL_Surface* icon = SDL_LoadBMP("icon.bmp");SDL_SetColorKey(icon, SDL_SRCCOLORKEY, SDL_MapRGB(icon->format, 255, 0, 255));SDL_WM_SetIcon(icon, 0);


And the "keyed" color just ends up being black.
BauerGL
BauerGL
Yes, I'm doing it like this:

SDL_Init(SDL_INIT_EVERYTHING)

.. that icon stuff ..

SDL_SetVideoMode(...)
Trenki
Trenki
OK, it looks like your setup is perfectly correct and looks just like the same as the example in the doc wiki. What OS are you on in between? Maybe that is the problem? In the header file the documentation does not state that a mask is automatically generated from colorkey or alpha.
Maybe you could try and generate your own mask and use use that to test if it works then?
BauerGL
BauerGL
I'm on Windows XP, dunno if that's good or bad. :)

I'll try to fix the mask manually, thanks for the tip.
BauerGL
BauerGL
Yes, the mask is working great!

I also found out that the reason (I suppose anyway) that the color key didn't work was that I didn't use 8 bit BMPs. I just converted my icon into 8 bit and now that works aswell.

Thanks for all the help!

Edit: Though I get some weird minor artifacts. For example if my icon consists of just a white circle in the middle (the rest is color keyed), I get some dark artifacts at the bottom of the circle.

[Edited by - BauerGL on September 7, 2007 6:57:22 AM]
nass84
nass84
Hi..

Can you please tell me how you fix that mask? is it the colorkey parameter of SDL_SetColorKey funciton?

Thanks and regards

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.