Skip to main content
gamedev.net
🔒 Locked

SDL alpha ...

Started by artois 2 replies 1.5k views
Original Post
artois
artois
Hello, i'm new to SDL development, i'm trying to do transparency, but it dont work. Here is the code :

 SDL_Surface *mySurface  = SDL_CreateRGBSurface(SDL_SRCALPHA | SDL_SWSURFACE |SDL_SRCCOLORKEY,256,256,32, rmask, gmask, bmask, amask);
 
 SDL_Rect myRect= {0,0,mySurface->w,mySurface->h};
 SDL_Rect half = {0,0,mySurface->w/2,mySurface->h/2};
 
 result= SDL_FillRect(mySurface,&myRect,SDL_MapRGB(mySurface->format,0,255,255));

 result=SDL_FillRect(mySurface,½,SDL_MapRGB(mySurface->format,0,255,0));

 result=SDL_SetColorKey(mySurface,SDL_SRCCOLORKEY, SDL_MapRGB(mySurface->format,0,255,0));

 result= SDL_BlitSurface(mySurface,&myRect,screen,&myRect);
 
   

I'm trying to make the small rectangle transparent, (half). I can do transpanrency with surface loaded from bmp file but not directly created like this one.. Can someone help me please
Gaiiden
Gaiiden
see if calling SDL_DisplayFormat() after you set the colorkey does the trick.
Drew Sikora
Executive Producer
GameDev.net
artois
artois
Cheer ! it worked !


Thanks !
Gaiiden
Gaiiden
Nice. As a further note, you should use this function everytime you load in an image, since blitting an surface of a different format to the main surface (i.e. - loading a 16bit image when you have a 32bit main surface) can be very slow if SDL has to convert the surface every blit rather than just once.
Drew Sikora
Executive Producer
GameDev.net

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.