Page 1 of 2

Removing glow around pictures

Posted: Mon May 10, 2010 4:36 pm
by pythip
I just finished a Tic-Tac-Toe (noughts and crosses), The only problem I have now is that whenever I put the X's and O's onto the screen I have a pink glow left around then from after I set the colour key to them. Is it a coding problem or would this be a problem with the picture I drew?

Code: Select all

SDL_Surface *load_image (const char *filename)
{
	SDL_Surface *img = IMG_Load(filename);
	SDL_Surface *nimg = NULL;
	if (img)
	{
	nimg = SDL_DisplayFormat(img);
	SDL_SetColorKey (nimg, SDL_SRCCOLORKEY, 0xff00ff);
	SDL_FreeSurface(img);
	}
	return (nimg);
}

Re: Removing glow around pictures

Posted: Mon May 10, 2010 4:41 pm
by pritam
Post the picture too.

Re: Removing glow around pictures

Posted: Mon May 10, 2010 5:05 pm
by pythip
Here is the picture
X O
X O
pieces.png (2.5 KiB) Viewed 1396 times

Re: Removing glow around pictures

Posted: Mon May 10, 2010 5:05 pm
by K-Bal
I bet you have anti-aliasing enabled.

Re: Removing glow around pictures

Posted: Mon May 10, 2010 5:08 pm
by Ginto8
Well just looking at it I can see that the X and O are antialiased, which means that the pink directly around it is NOT the colorkey color. That would be your problem. ;)

Re: Removing glow around pictures

Posted: Mon May 10, 2010 5:17 pm
by K-Bal
Ginto8 wrote:Well just looking at it I can see that the X and O are antialiased, which means that the pink directly around it is NOT the colorkey color. That would be your problem. ;)
Yep, I posted right before the picture was uploaded.

You should use a picture format with alpha channel.

Re: Removing glow around pictures

Posted: Mon May 10, 2010 5:36 pm
by Ginto8
K-Bal wrote:You should use a picture format with alpha channel.
Unfortunately that doesn't quite work with SDL. If it were OpenGL (or even SFML IIRC), it'd be fine. But SDL's alpha is crazy slow so colorkeying is his best bet.

Re: Removing glow around pictures

Posted: Mon May 10, 2010 5:42 pm
by Live-Dimension
This is your circle enlarged by 800%
AA.png
AA.png (4.08 KiB) Viewed 1354 times
The left one is what it is like now. A colorkey works by removing one specific color while keeping the rest there. The right one is the pink removed as a colorkey would. Notice how there are different shades between pink and black? That's the effect of Anti-Aliasing. Wen you make your X+O, either do it without enabling antialising, or use PNG which has alpha-transparency. How you do this depends on your software naturally.

Re: Removing glow around pictures

Posted: Mon May 10, 2010 6:03 pm
by pythip
I have been fiddling with gimp to get rid of the Anti-Aliasing, could not figure it out, so I remade the picture, I kept it as a .png but I used the text tool. The text tool has a button that lets you turn off the Anti-Aliasing, so it worked like a charm. Thanks everyone for the help!

Re: Removing glow around pictures

Posted: Mon May 10, 2010 6:47 pm
by Bakkon
Ginto8 wrote:
K-Bal wrote:You should use a picture format with alpha channel.
Unfortunately that doesn't quite work with SDL. If it were OpenGL (or even SFML IIRC), it'd be fine. But SDL's alpha is crazy slow so colorkeying is his best bet.
SDL_image would be plenty fine for a game of Tic-Tac-Toe.

Re: Removing glow around pictures

Posted: Mon May 10, 2010 6:52 pm
by Ginto8
Bakkon wrote:
Ginto8 wrote:
K-Bal wrote:You should use a picture format with alpha channel.
Unfortunately that doesn't quite work with SDL. If it were OpenGL (or even SFML IIRC), it'd be fine. But SDL's alpha is crazy slow so colorkeying is his best bet.
SDL_image would be plenty fine for a game of Tic-Tac-Toe.
Yes, but using alpha colors will be slow as hell compared to colorkeying.

Re: Removing glow around pictures

Posted: Mon May 10, 2010 7:25 pm
by Bakkon
Ginto8 wrote:Yes, but using alpha colors will be slow as hell compared to colorkeying.
I've used alpha images in a shmup with hundreds of objects on screen and it still runs well over 200 FPS. Its kind of a non-issue unless you're porting SDL to the DS or something.

Re: Removing glow around pictures

Posted: Mon May 10, 2010 7:49 pm
by Ginto8
Bakkon wrote:
Ginto8 wrote:Yes, but using alpha colors will be slow as hell compared to colorkeying.
I've used alpha images in a shmup with hundreds of objects on screen and it still runs well over 200 FPS. Its kind of a non-issue unless you're porting SDL to the DS or something.
Oh you musta been using SDL_HWSURFACE and other hw accelerated stuff... I forgot SDL had that ;)

Re: Removing glow around pictures

Posted: Tue May 11, 2010 2:40 am
by K-Bal
The essence of all is: use SFML ;)

Re: Removing glow around pictures

Posted: Tue May 11, 2010 5:32 am
by lotios611
Ginto8 wrote:Yes, but using alpha colors will be slow as hell compared to colorkeying.
Oh you musta been using SDL_HWSURFACE and other hw accelerated stuff... I forgot SDL had that ;)
I think you two are talking about 2 different things. What K-Bal is doing is using PNG's that already have part of the image transparent, so all SDL need to do is draw the non-transparent pixels. What you're talking about is having SDL calculate the alpha at run-time.