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

Author Topic: sf::Texture and MaskFromColor?  (Read 3984 times)

0 Members and 1 Guest are viewing this topic.

Clairvoire

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - Clairvoire
    • View Profile
    • http://clairvoire.deviantart.com
sf::Texture and MaskFromColor?
« on: September 16, 2011, 11:43:26 am »
Hello!  I have not updated SFML since March, when you changed from SVN to GIT.  (Could have put a warning in the commit log, thought the project died!)

My Question: I have a .png where the black colour in the image should be transparent, and setting the colour of the sf::Sprite determines the colour of the internal sprite.  (monochrome colour for font, this used to work)

sf_image->CreateMaskFromColor(sf::Color::Black);
sf_sprite->setImage(sf_image);
sf_sprite->setColor(some color);

How would I do this with textures now?  When I do the above, but with textures instead.  (the sf::Texture is created from the masked sf::Image) all it produces is a solid rectangle of whatever colour I set the sprite to.

Thanks in advance!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Texture and MaskFromColor?
« Reply #1 on: September 16, 2011, 11:51:40 am »
Code: [Select]
sf::Image image;
image.LoadFromFile(...);
image.CreateMaskFromColor(...);

sf::Texture texture;
texture.LoadFromImage(image);

sf::Sprite sprite;
sprite.SetTexture(texture);


But if you have a PNG then it would be much simpler to convert that black background to an alpha channel.
Laurent Gomila - SFML developer

Clairvoire

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - Clairvoire
    • View Profile
    • http://clairvoire.deviantart.com
sf::Texture and MaskFromColor?
« Reply #2 on: September 16, 2011, 12:11:21 pm »
... I'm a moron, I forgot to assign the texture to the sprite.  No wonder it was doing a solid colour.  

Thanks for the fast response!  It took having to see it plain daylight for me, bah...