SDL_LoadBMP bitmap with alpha

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!

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;On Thu, Oct 14, 2010 at 9:23 PM, bu6w3uj <borisd at zworg.com> wrote:

Thank you Andy, that did the magic.