Advertisement

transparency in SDL

Started by July 09, 2004 11:17 AM
3 comments, last by sand_man 20 years, 4 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
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).
Advertisement
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