Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I tried to upload the image via sfml probably in all possible ways, but I got an error in the console
My code:
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <iostream>
using namespace std;
int main()
sf::RenderWindow window(sf::VideoMode(800, 600), "Test");
sf::Texture texture;
int i=0;
if (!texture.loadFromFile("box.jpg"))
std::cout << "Error!";
window.close();
return 1;
sf::Sprite sprite;
sprite.setTexture(texture);
sf::Event event=sf::Event();
while (window.isOpen())
if (event.type == sf::Event::Closed)
window.close();
window.draw(sprite);
window.clear();
window.display();
return 0;
Maybe I'm doing something wrong, I'm a beginner c++ and sfml developer.
My settings:
https://i.stack.imgur.com/OF9FA.png
https://i.stack.imgur.com/u2ZSC.png
The file with the picture is in all folders starting from the repos
I dragged the file over all folders in the solution folder, starting from the very first folder ending with the x64 folder, all without success, I searched the question on the Internet, I did not find. \
I tried to move the image to the C folder and specified the path to the image C:\\box.jpg, I got an error in the console:Failed to load image "╨°│╕;☻C:\box.jpg
‼b√⌂Г0b√⌂9Ц ☻ў⌂ ♥X☻ ў⌂Я0b√⌂И·/WJИ·/WJ¶·/WJж╬▀pp↓ut ☻ў⌂)w ☻ў⌂☺p↓│▼√⌂╜О ☻ў⌂☺P?Ь╡;☻└ЙЪ╡;☻`t ☻ў⌂╬u ☻ў⌂Ё ☻ў⌂ Є ☻ў⌂аK♥ў⌂ИK♥ў⌂Оt ☻ў⌂╛w ☻ў⌂¶v╞р√⌂@¶WJб&╢с√⌂0√ ш♦0√ ╨♦↓
–
–
sf::Texture texture;
int i = 0;
if (!texture.loadFromFile("box.jpg")) // check file path or you can execute the program from command line to make sure
std::cout << "Error!";
window.close();
return 1;
sf::Sprite sprite;
sprite.setTexture(texture);
while (window.isOpen())
sf::Event event;
while (window.pollEvent(event)) // poll event
if (event.type == sf::Event::Closed)
window.close();
window.clear(); // clear first
window.draw(sprite);
window.display();
return 0;
If you don't use the absolute file path the folder tree is as follows:
C:\...\SFML
├───SFML // the image file needs to be here to run from IDE
│ └───x64
│ └───Debug
└───x64
└───Debug // the image file needs to be here to run from command line
└───Release // the image file needs to be here to run from command line
Who has the same problem go to the project -> properties -> configuration properties -> advanced -> use debugging libraries, by default it is yes, you need to set it to default or "no".
Translated through a translator, the translation may not be accurate
(Sorry for my English)
–
Make sure the image you want to load is in the same folder as the c++ project file. it doesn't need to be anywhere else but there.
Also make sure your file is named as it is in your program (box.jpg).
You should also move window.clear();
to above window.draw(sprite);
or the image wont be displayed.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.