SDL2 - "SDL_SetColorKey()" Transparent Surface Pixels Not Working?[SOLVED]


#1

Hi,

Working on a BMP Font system now.
Have a problem with setting “SDL_SetColorKey” of the temporary surface.
(color key is set to RED, which is the red background of the “CharTemp.bmp”)
I need the RED to be transparent in the final texture…

bool Visuals::LoadFontBMPs(void)
{
Uint32 textureFormat;
int textureAccess;
int textureWidth;
int textureHeight;

    SDL_Surface *spriteSheet = NULL;
    SDL_Surface *boxTemp = NULL;
    SDL_Rect dstRect;
    SDL_Rect srcRect;

    spriteSheet = SDL_LoadBMP("data/font/FontBMP.bmp");
    if (!spriteSheet)
    {
        printf( "SDL2 load BMP failed: %s\n", SDL_GetError() );
        CoreFailure = true;
        return(false);
    }

    dstRect.x = 0;
    dstRect.y = 0;
    dstRect.w = 9;
    dstRect.h = 9;

    srcRect.x = 1;
    srcRect.y = 1;
    srcRect.w = 9;
    srcRect.h = 9;

    for (int index = 32; index < 127; index++)
    {
        boxTemp = SDL_LoadBMP("data/font/CharTemp.bmp");
        if (!boxTemp)
        {
            printf( "Image loading failed: %s\n", SDL_GetError() );
            CoreFailure = true;
            return(false);
        }

        // Below is NOT working?
        SDL_SetColorKey( boxTemp, true, SDL_MapRGB(boxTemp->format, 255, 0, 0) );

        SDL_BlitSurface(spriteSheet, &srcRect, boxTemp, &dstRect);

        srcRect.x+=10;

        FontChars[index].Texture = SDL_CreateTextureFromSurface(Renderer, boxTemp);

        SDL_QueryTexture(FontChars[index].Texture, &textureFormat, &textureAccess, &textureWidth, &textureHeight);
        FontChars[index].TextureWidthOriginal = textureWidth;
        FontChars[index].TextureHeightOriginal = textureHeight;

        SDL_FreeSurface(boxTemp);
    }

    SDL_FreeSurface(spriteSheet);

    return(true);
}

Full clean source below:
http://fallenangelsoftware.com/stuff/files/C64GKGM2/alpha/C64GKGM2.zip

Image of issue below:

Thanks!

Jesse


#2

Got it working… needed to change the “CharTemp.bmp” from 32bit with alpha to 24bit without alpha.
Thanks!

Jesse