Here’s the code I had that had the problem, but had fixed:
SDL_Surface *load_image(const char *pathname)
SDL_Surface *surface, *temp;
sprintf(buf, “images/%s”, pathname);
temp = IMG_Load(buf);
fatal_error(“Could not load %s!”, buf);
blue = SDL_MapRGB(temp->format, 0, 0, 255);
SDL_SetColorKey(temp, SDL_SRCCOLORKEY | SDL_RLEACCEL, blue);
surface = SDL_DisplayFormat(temp);
Previously, I was using the global blue variable, which was generated by this line elsewhere (in my init() function):
blue = SDL_MapRGB(screen->format, 0x00, 0x00, 0xff);
Problem was that the screen colors apparently didn’t match my image colors. They would in ‘surface’ after the SDL_DisplayFormat(temp) call, of course. So my global blue above mapped to the value 255, but the blue that mapped to “temp” was 4 million and something. A very different number.
Anyway, use the above function, or a variation on it, and it should work. The transparent color here is full blue, but you said you use black, so make that 255 a 0 instead.
-Jason----- Original Message -----
From: Richard Perrine
To: sdl at libsdl.org
Sent: Thursday, March 21, 2002 2:59 PM
Subject: Re: [SDL] setcolorkey
Still not getting it. What did you do to solve the problem? By the way, what did you mean that you were not sure what the RGB macro or function was? Should the colorkey value be a single integer? Could you give an example of the SetColorKey function in a program that successfully blits a bmp with transparency?
Jason Hoffoss <jason at hoffoss.com> wrote:
----- Original Message -----
From: Richard Perrine
Sent: Thursday, March 21, 2002 8:54 AM
Subject: [SDL] setcolorkey
The SetColorKey function seems pretty straight forward, but my blitted bitmaps still show the black area around the actual image of the bmp. I set the colorkey to black, ie. SDL_SetColorKey(bmp,SDL_SRCCOLORKEY|SDL_RLEACCEL,RGB(0,0,0));
Not sure what this RGB macro or function is, but you want to make sure you map a color in the bmp's colorspace, rather than the screen's colorspace. They each have a seperate set of colors, so using the screen's black color may not match what is black in the bmp.
I just had the same sort of problem earlier today, and this was what I was doing wrong.
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards?