Hi, I’m trying to change a 24 bit surface with a color key to a 32 bit
surface with alpha channel. Because there is the color key, I want all
pixels in the new surface with the color matching the color key has an
alpha channel of 0 (or transparent). I’ve tried making a new 32 bit
surface with alpha channel 0 and blit the 24 bit surface to it but it
didn’t work. In fact all the colors are wrong in the new surface. How do I
do that? Is there anything wrong with my code? Thanks in advance.
BTW, this is the code:
if ( (surface = SDL_LoadBMP(“test.bmp”)) )
{
char color=surface->flags&SDL_SRCCOLORKEY;
SDL_SetColorKey(surface, SDL_SRCCOLORKEY, SDL_MapRGB(surface->format,
0, 0, 0));
/* From SDL Documentation.
Create a 32-bit surface with the bytes of each pixel in R,G,B,A order,
as expected by OpenGL for textures */
SDL_Surface *tempSur;
Uint32 rmask, gmask, bmask, amask;
/* SDL interprets each pixel as a 32-bit number, so our masks must depend
on the endianness (byte order) of the machine */
#if not SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif
tempSur = SDL_CreateRGBSurface(SDL_SWSURFACE, surface->w, surface->h,
32,rmask, gmask, bmask, amask);
if(tempSur == NULL) {
fprintf(stderr, "CreateRGBSurface failed: %s\n", SDL_GetError());
exit(1);
}
SDL_SetAlpha(tempSur, SDL_SRCALPHA, 0);
SDL_BlitSurface(surface,NULL,tempSur,NULL);
SDL_FreeSurface( surface );
surface=tempSur;
}
else {
fprintf(stderr, “Cannot load BMP: %s\n”, SDL_GetError());
exit(1);
}
Fare thee well,
Bawenang R. P. P.----------------
ERROR: Brain not found. Please insert a new brain!
?Do nothing which is of no use.? - Miyamoto Musashi.
“I live for my dream. And my dream is to live my life to the fullest.”