Setcolorkey

Hi,

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));

I also have the alpha active, ie. SDL_SetAlpha(bmp, SDL_SRCALPHA|SDL_RLEACCEL, 255);

What am i doing wrong? It obviously looks great when the bmp goes over black areas, but when it goes over colored areas, the black area of the bmp boundary is revealed. Are there other issues that I need to pay close attention to in order for the bmp to show only the actual image w/o the boundary? Eg. updating the screen, updating scene, etc.

THanks again. I truly am grateful for all your help. I hope to be as knowledgeable about SDL with your help.

richard---------------------------------
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards?

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));

I also have the alpha active, ie. SDL_SetAlpha(bmp,
SDL_SRCALPHA|SDL_RLEACCEL, 255);

This could be the problem. AFAIK, you can only use EITHER alpha values
OR a color key, not both at the same time. If this doesn help, send me
an example file and I’ll have a look at it.

Bye,

– Karl

Hi,

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.

-Jason----- Original Message -----
From: Richard Perrine
To: SDLgroup
Sent: Thursday, March 21, 2002 8:54 AM
Subject: [SDL] setcolorkey

Thanks jason!

That makes perfect sense to me. I’ll give a try.

richard

— Jason Hoffoss wrote:> ----- Original Message -----

From: Richard Perrine
To: SDLgroup
Sent: Thursday, March 21, 2002 8:54 AM
Subject: [SDL] setcolorkey

Hi,

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.

-Jason


Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards?
http://movies.yahoo.com/

Jason,
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?
Thanks again!
Richard
Jason Hoffoss wrote: ----- Original Message ----- From: Richard Perrine To: SDLgroup Sent: Thursday, March 21, 2002 8:54 AMSubject: [SDL] setcolorkey

Hi,

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.

-Jason---------------------------------
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards?

Here’s the code I had that had the problem, but had fixed:

SDL_Surface *load_image(const char *pathname)
{
char buf[1024];
Uint32 blue;
SDL_Surface *surface, *temp;

sprintf(buf, “images/%s”, pathname);
temp = IMG_Load(buf);
if (!temp)
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);
SDL_FreeSurface(temp);

return surface;
}

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

Jason,

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?

Thanks again!

Richard

Jason Hoffoss <jason at hoffoss.com> wrote: 

  ----- Original Message ----- 
  From: Richard Perrine 
  To: SDLgroup 
  Sent: Thursday, March 21, 2002 8:54 AM
  Subject: [SDL] setcolorkey


  Hi,

  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.

   -Jason

Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards?