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

Author Topic: sfml noob, displaying image problem  (Read 1056 times)

0 Members and 2 Guests are viewing this topic.

parinho7

  • Newbie
  • *
  • Posts: 1
    • View Profile
sfml noob, displaying image problem
« on: April 01, 2013, 07:31:20 pm »
Hi, I am new to sfml and I use the 2.0 rc version.

I have a problem displaying an image on the screen.
This is the piece of code I wrote:

Quote
sf::Texture texture;
if (!texture.loadFromFile("block.bmp"))
   return false;

sprite.setTexture(texture);
sprite.setPosition(100, 25);

The problem is, I only get a white image instead of the normal colorized one. Why is that and how can I fix it?

Thanks in advance!

EDIT: Sorry, I just read this

Quote
It is important to note that the sf::Sprite instance doesn't copy the texture that it uses, it only keeps a reference to it. Thus, a sf::Texture must not be destroyed while it is used by a sf::Sprite

so I know what the problem is now!
« Last Edit: April 01, 2013, 07:40:24 pm by parinho7 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: sfml noob, displaying image problem
« Reply #1 on: April 01, 2013, 07:42:14 pm »
Welcome to SFML and the forum! :)

To post code you should use the code=cpp tag instead of the quote tag.

As for your question, there's an answer in the FAQ, you might want to check it out. If you still don't get it, then you can come back and ask again. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/