Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::CreateMaskFromColor doesn't work properly?  (Read 1920 times)

0 Members and 1 Guest are viewing this topic.

mudale222

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
sf::CreateMaskFromColor doesn't work properly?
« 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???




eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: sf::CreateMaskFromColor doesn't work properly?
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

mudale222

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: sf::CreateMaskFromColor doesn't work properly?
« Reply #2 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.


Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::CreateMaskFromColor doesn't work properly?
« Reply #3 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):


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


p.s. You can press ALT+PrintScreen to capture just the current window, instead of the entire desktop.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

SeriousITGuy

  • Full Member
  • ***
  • Posts: 123
  • Still learning...
    • View Profile
Re: sf::CreateMaskFromColor doesn't work properly?
« Reply #4 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! ;)