SFML community forums

Help => Graphics => Topic started by: mudale222 on May 25, 2015, 03:39:11 pm

Title: sf::CreateMaskFromColor doesn't work properly?
Post by: mudale222 on May 25, 2015, 03:39:11 pm
hi
i'm trying to build little shooting game. so, i'm trying to adding a scope/sight.
I want to remove the white background so the target can be seen.
I'm using this simple code:
_sight_object_image.loadFromFile("sight.png");
        _sight_object_image.createMaskFromColor(sf::Color::White);
        _sight_object_texture.loadFromImage(_sight_object_image);
        _sight_Object_sprite.setTexture(_sight_object_texture);

But what happend is that in all the 'round' place, the function doesn't seem to work properly..
Any ideas???

(http://i59.tinypic.com/e5pr2p.png)

(http://i59.tinypic.com/2cwsajr.png)
Title: Re: sf::CreateMaskFromColor doesn't work properly?
Post by: eXpl0it3r on May 25, 2015, 03:57:13 pm
The created scope used anti-aliasing to smooth the edges, this technique uses a mix of the object and background color as to trick the eyes into thinking it's "smooth". This mixed colors aren't just white, so your color masked won't remove them. At best you just create the scope on a transparent background instead and save it in a format that supports transparent colors, e.g. PNG.
Title: Re: sf::CreateMaskFromColor doesn't work properly?
Post by: mudale222 on May 25, 2015, 04:53:22 pm
thx man
I didn't know about that option of deleting parts in the images so that they become transperting.
Did that, some color play, smooth on, and the result is good.

(http://i58.tinypic.com/2w1uzq9.png)
Title: Re: sf::CreateMaskFromColor doesn't work properly?
Post by: Hapax on May 25, 2015, 04:57:33 pm
This is a close up of your original scope and shows why removing white doesn't remove the bits that aren't just black or red (as eXpl0it3r already explained):
(http://i.imgur.com/lodx1f9.jpg)

I see you have a new scope now but, because I'm nice, here's a version of that original scope with transparency just for you  ;)
(http://i.imgur.com/V5V01cb.png)

p.s. You can press ALT+PrintScreen to capture just the current window, instead of the entire desktop.
Title: Re: sf::CreateMaskFromColor doesn't work properly?
Post by: SeriousITGuy on May 26, 2015, 11:28:42 am
p.s. You can press ALT+PrintScreen to capture just the current window, instead of the entire desktop.
Windows Admin for 12 years now and didn't know that trick! Give that man a medal! ;)