The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL_LoadBMP bitmap with alpha
bu6w3uj


Joined: 13 Oct 2010
Posts: 2
I am trying to load bmp file that has alpha channel, but I am not getting expected result on the screen. Image is displayed but alpha channel information is ignored. Am I doing something wrong, or alpha bmp's are not supported in current SDL version?

Code goes something like this (for the clarity I have omitted error checking):

Code:

// init
SDL_Init( SDL_INIT_VIDEO);
SDL_Surface* screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BITSPERPIXEL, SDL_HWSURFACE | SDL_DOUBLEBUF);

// clear screen
SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 128, 128, 128));

// load bmp that has alpha chanel (32 bit/pixel)
SDL_Surface* bmp = SDL_LoadBMP("alpha.bmp");

// set flag for alpha channnel
SDL_SetAlpha(bmp, SDL_SRCALPHA /*| SDL_RLEACCEL*/, SDL_ALPHA_OPAQUE);

// show it
SDL_BlitSurface(bmp, 0, screen, 0);
SDL_Flip(screen);
SDL_FreeSurface(bmp);


Thanks!
SDL_LoadBMP bitmap with alpha
Andy Hefner
Guest

On Thu, Oct 14, 2010 at 9:23 PM, bu6w3uj wrote:

Quote:
I am trying to load bmp file that has alpha channel, but I am not getting expected result on the screen. Image is displayed but alpha channel information is ignored. Am I doing something wrong, or alpha bmp's are not supported in current SDL version?

I recall having to modify the pixel format the get the desired alpha
blending. Try adding the following:

bmp->format->Amask = 0xFF000000;
bmp->format->Ashift = 24;
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
bu6w3uj


Joined: 13 Oct 2010
Posts: 2
Thank you Andy, that did the magic.