Alpha/Transparency from BMP files

After using SDL_LoadBMP to load a small bitmap, I want to blit it to a
hardware surface with transparent sections.

  • I create the destination surface with
    Screen = SDL_SetVideoMode(XRes, YRes, Bpp,
    SDL_HWSURFACE|SDL_HWPALETTE|SDL_DOUBLEBUF);

  • Load the bitmap
    image = SDL_LoadBMP(imagename);

  • Set ColorKey and Alpha information
    SDL_SetColorKey(image, 0, SDL_MapRGB(Screen->format, 0xFF, 0x00, 0xFF));
    SDL_SetAlpha(image, SDL_SRCALPHA, 255); //tried with and without this line

  • Then blit it and flip it.
    SDL_BlitSurface(image, NULL, Screen, &dest);
    SDL_Flip(Screen);

The ugly purple pixels show, when I think they shouldn’t. I’m using NT 4.0,
Visual Studio 6.

Am I doing something wrong?
Does LoadBMP set up a surface that doesn’t support transparency or Alpha?
Do I need to do something to my Screen before blitting?
Is SDL broke? I hope not - I really like it so far.

Also, can someone lay out the procedure or point to a reference for using
ImageLib with SDL on the NT and Linux platforms?

  • Scott Russell

Do all the ugly purple pixels show, colorkeys are very exact and when
images are antialiased if one channel is even one off it will be
blitted.

Phoenix Kokido
members.xoom.com/kokido
@Wes_Poole

Scott Russell wrote:

After using SDL_LoadBMP to load a small bitmap, I want to blit it to a
hardware surface with transparent sections.

  • I create the destination surface with
    Screen = SDL_SetVideoMode(XRes, YRes, Bpp,
    SDL_HWSURFACE|SDL_HWPALETTE|SDL_DOUBLEBUF);

  • Load the bitmap
    image = SDL_LoadBMP(imagename);

  • Set ColorKey and Alpha information
    SDL_SetColorKey(image, 0, SDL_MapRGB(Screen->format, 0xFF, 0x00, 0xFF));
    SDL_SetAlpha(image, SDL_SRCALPHA, 255); //tried with and without this line

  • Then blit it and flip it.
    SDL_BlitSurface(image, NULL, Screen, &dest);
    SDL_Flip(Screen);

The ugly purple pixels show, when I think they shouldn’t. I’m using NT
4.0,> Visual Studio 6.

Am I doing something wrong?
Does LoadBMP set up a surface that doesn’t support transparency or Alpha?
Do I need to do something to my Screen before blitting?
Is SDL broke? I hope not - I really like it so far.

Also, can someone lay out the procedure or point to a reference for using
ImageLib with SDL on the NT and Linux platforms?

  • Scott Russell

Yes - I assumed this was the problem at first, and used a non-aliasing tool
to check the bitmaps - the pixels are all 0xFF00FF.

  • Scott

Fixed it, I think. It required an SDL_ConvertSurface after the load. Seems
to improve performance, too.

  • Scott