'How can I load an image in C++ using SFML library?
How can I load an image in C++ using SFML library?
I am making a game using C++, and for textures of bonuses I want to upload *.png from directory instead of creating them in *.cpp file. How can I do this using SFML library?
Solution 1:[1]
Try something like:
sf::Texture texture;
if (!texture.loadFromFile("path/to/myTexture.png")) {
perror("Couldn't load texture \"myTexture\".");
return;
}
You can then put it on spirte:
sf::Sprite sprite;
sprite.setTexture(texture);
and finally display it:
sprite.setPosition(x,y);
window.draw(sprite);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jakub Bednarski |
