SFML community forums

Help => Graphics => Topic started by: geekz on August 25, 2021, 06:29:22 pm

Title: transparent texture into sprite but still shows white background
Post by: geekz on August 25, 2021, 06:29:22 pm
Hi everybody,

I'm just learning SFML and I'm having a trouble to load a picture without background - my current screen is black and I'd like to put sprite at screen (the .png picture i have is transparent) but still shows white background under.
Is there any simple way to make the texture/sprite transparent?

My code:
    sf::Texture texture;
    sf::Sprite sprite;
    if (!texture.loadFromFile("spacetest2.png"))
    {
        // error...
        std::cout << "doesnt work" << std::endl;
    }
    sprite.setTexture(texture);
    window.draw(sprite);
    window.display();

I've attached pictures below:
Title: Re: transparent texture into sprite but still shows white background
Post by: kojack on August 25, 2021, 07:04:58 pm
That image doesn't have transparency, the white/grey grid is actually part of it.
Title: Re: transparent texture into sprite but still shows white background
Post by: geekz on August 25, 2021, 07:25:54 pm
Ah, so I just need to find another picture that is actually transparent and use same code as I have, that's it?
Title: Re: transparent texture into sprite but still shows white background
Post by: eXpl0it3r on August 25, 2021, 09:51:38 pm
Yes  :)
Title: Re: transparent texture into sprite but still shows white background
Post by: Switchboy on August 26, 2021, 02:33:15 pm
Next time when you save double check if transparancy is checked!  ;)

Made it transparant for you.
Title: Re: transparent texture into sprite but still shows white background
Post by: geekz on August 30, 2021, 04:16:14 pm
thank you <3, and yes I really need to look at pictures better  :P