Alpha Transparency Problems (using SDL)

Started by
3 comments, last by Xelse 18 years, 7 months ago
ARGH! I have been trying for the longest time to do some transparency with alpha channel BMPs. I've looked at a bunch of SDL examples and I think I'm following what they do to the letter, but it always shows the parts that are supposed to be transparent! I'm very new to this but so far my complete code will draw a tiled map and a hero on the screen. To reiterate, the problem is the hero's transparency doesn't work. here's the code that I use:
Quote: temp = SDL_LoadBMP("hero.bmp"); SDL_SetColorKey(temp, SDL_SRCCOLORKEY, SDL_MapRGB(temp->format, 0, 255, 0)); hero = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); . . some code here for src and dest . SDL_BlitSurface(hero, &src, screen, &dest); SDL_UpdateRects(screen, 1, &dest);
I draw the map using a similar method but without the SDL_SetColorKey. I think maybe I'm drawing to the screen in a wrong way or maybe my BMP is just fucked up but I really don't have any real clues. the full source code can be seen here: http://rain.ath.cx:69/lufia/ If anyone can give me any pointers I'd be very grateful!
Advertisement
try switching some lines around:

Quote:

temp = SDL_LoadBMP("hero.bmp");
hero = SDL_DisplayFormat(temp);
SDL_SetColorKey(hero, SDL_SRCCOLORKEY, SDL_MapRGB(hero->format, 0, 255, 0));

SDL_FreeSurface(temp);


Sidra Headquarters
Game engine is currently at version 0.9.8! Currently Down
Nope, didn't work for me :(

and the working examples show the original way I wrote it.
Are you sure the color you want to use as the color key is actually the color you passed to SDL_SetColorKey(full blue)? Especially if you set the color key AFTER you set the surface to the display format since the rgb values may change slightly depending on the color depth of the original bitmap on disk and the display format. Use a getpixel function to see if one of the supposedly transparent pixels has the rgb values you want.
Evillive2
i believe bmp on disk is 32b color depth
and i'm trying to use full green as transparent (not full blue?)

it's funny cause i keep reading transparency is easy with SDL haha?

This topic is closed to new replies.

Advertisement