🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

transparency in SDL

Started by
3 comments, last by sand_man 19 years, 12 months ago
i have a small bitmap image, 29x29, of a circle ball. i want to know how to make the area outside the ball transparent so you cant see it when moving across the differrent colored background. any help at all is greatly appreciated
Advertisement
Paint the background of the image in a specific color (e.g. magenta) and

ball_surface = SDL_LoadBMP("ball.bmp");SDL_SetColorKey( ball_surface, SDL_SRCCOLORKEY, 0x00ff00ff );


should work (0x00ff00ff is the color that will not be drawn).
Or use SDL_image and save your images as png files with alpha channel.
http://www.libsdl.org/projects/SDL_image/
Writing errors since 10/25/2003 2:25:56 AM
Here's an easier way:

SDL_Surface *Foo = SDL_LoadBMP("Foo.bmp");
SDL_SetColorKey(Foo, SDL_SRCCOLORKEY, SDL_MapRGB(Foo->format, Red, Green, Blue));

where you replace Red, Green and Blue with the appropiate RGB value of the transparent pixel in the image.
thanks a lot guys

This topic is closed to new replies.

Advertisement