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

Author Topic: transparent texture into sprite but still shows white background  (Read 5415 times)

0 Members and 1 Guest are viewing this topic.

geekz

  • Newbie
  • *
  • Posts: 7
    • View Profile
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:
« Last Edit: August 25, 2021, 06:36:25 pm by geekz »

kojack

  • Sr. Member
  • ****
  • Posts: 299
  • C++/C# game dev teacher.
    • View Profile
Re: transparent texture into sprite but still shows white background
« Reply #1 on: August 25, 2021, 07:04:58 pm »
That image doesn't have transparency, the white/grey grid is actually part of it.

geekz

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: transparent texture into sprite but still shows white background
« Reply #2 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Re: transparent texture into sprite but still shows white background
« Reply #3 on: August 25, 2021, 09:51:38 pm »
Yes  :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Switchboy

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: transparent texture into sprite but still shows white background
« Reply #4 on: August 26, 2021, 02:33:15 pm »
Next time when you save double check if transparancy is checked!  ;)

Made it transparant for you.

geekz

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: transparent texture into sprite but still shows white background
« Reply #5 on: August 30, 2021, 04:16:14 pm »
thank you <3, and yes I really need to look at pictures better  :P

 

anything