Jump to content
  • Advertisement
Sign in to follow this  
Xelse

Alpha Transparency Problems (using SDL)

This topic is 4768 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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);


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!