Removing glow around pictures

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

pythip
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 33
Joined: Sat Apr 24, 2010 11:25 pm

Removing glow around pictures

Post 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);
}
pritam
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 991
Joined: Thu Nov 13, 2008 3:16 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Amiga, PSOne, NDS
Programming Language of Choice: C++
Location: Sweden

Re: Removing glow around pictures

Post by pritam »

Post the picture too.
pythip
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 33
Joined: Sat Apr 24, 2010 11:25 pm

Re: Removing glow around pictures

Post by pythip »

Here is the picture
X O
X O
pieces.png (2.5 KiB) Viewed 1116 times
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Removing glow around pictures

Post by K-Bal »

I bet you have anti-aliasing enabled.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Removing glow around pictures

Post 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. ;)
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Removing glow around pictures

Post 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.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Removing glow around pictures

Post 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.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Live-Dimension
Chaos Rift Junior
Chaos Rift Junior
Posts: 345
Joined: Tue Jan 12, 2010 7:23 pm
Favorite Gaming Platforms: PC - Windows 7
Programming Language of Choice: c++;haxe
Contact:

Re: Removing glow around pictures

Post by Live-Dimension »

This is your circle enlarged by 800%
AA.png
AA.png (4.08 KiB) Viewed 1074 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.
Image
pythip
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 33
Joined: Sat Apr 24, 2010 11:25 pm

Re: Removing glow around pictures

Post 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!
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: Removing glow around pictures

Post 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.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Removing glow around pictures

Post 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.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: Removing glow around pictures

Post 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.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Removing glow around pictures

Post 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 ;)
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Removing glow around pictures

Post by K-Bal »

The essence of all is: use SFML ;)
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: Removing glow around pictures

Post 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.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
Post Reply