int apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination)
{
SDL_Rect rect;
rect.x = x;
rect.y = y;
//Tryck på ytan
SDL_BlitSurface(source, NULL, destination, &rect);
return 0;
}
int main ( int argc, char** argv )
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Init(SDL_INIT_TIMER);
SDL_Surface* screen = SDL_SetVideoMode( 720, 480, 24, SDL_SWSURFACE );
SDL_Surface* player = SDL_LoadBMP("/home/mattias/Pictures/GIMPED/Tennsoldat från sidan.bmp"); //Loads a sprite with 0 255 255 background colour
SDL_Surface* background = SDL_LoadBMP("/home/mattias/CodeBlocks/Spelet/sprites/background3.bmp");
player = SDL_DisplayFormat(player); //Makes the player have the same properties as the screen, not really needed
Uint32 alpha = SDL_MapRGB( player->format, 0, 255, 255 ); //Specifies the colour which is going to be interpreted as alpha colour
SDL_SetColorKey( player, SDL_SRCCOLORKEY, alpha ); //Actually sets the pixel with this colour to alpha
apply_surface(0,0,background,screen);
apply_surface(720/2,480-64,player,screen);
SDL_Flip(screen);
SDL_Delay(3000);
SDL_Quit();
}
This is a modified extraction from my game. Despite having done the SetColorKey thing I still get my blue(0 255 255) border around my sprite. But if I set the bits per pixel to 24 it works. The sprite is in 24 bits I think and the colour is correct. In another part of the code I create a surface within SDL and fill this with alpha and it becomes transparent even with 32 BPP. Over at the SDL channel on Freenode they say that my VideoMode should have 32 bits so I would like to keep it that way. Why doesn't this work as it is?
I've attached the sprite and the background to this post. Just replace the file locations and you should be able to run this.