Jump to content
  • Advertisement
Sign in to follow this  
Epicurus

Problem using transparency

This topic is 2597 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



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.

Share this post


Link to post
Share on other sites
Advertisement
Hejsan!

I don't know why but if I change SDL_LoadBMP to IMG_Load it works. IMG_Load is part of SDL_image and supports more image formats.

I'm quite sure you shouldn't call SDL_Init more than once. Instead pass all the flags in the same call like this
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);

Share this post


Link to post
Share on other sites
On the topic of:

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.[/quote]

It looks like SDL 1.3 is changing things up a little on the video mode and window creation:

LINK

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!