Search code examples
c++graphicstexturesspritesfml

How to make color as alpha (remove a color) in SFML?


I have a texture in the sprite and I want to make background invisible (white color).

sf::Texture texBohatera;
texBohatera.loadFromFile("bohater.png");

sf::Sprite bohater;
bohater.setTexture(texBohatera);

Solution

  • Something like this should work.

    sf::Image image;
    image.LoadFromFile("bohater.png");
    image.CreateMaskFromColor(sf::Color::White);
    
    sf::Texture texBohatera;
    texBohatera.LoadFromImage(image);
    
    sf::Sprite bohater;
    bohater.SetTexture(texture);
    

    (Disclaimer, I didn't test it because I don't want to install SFML)