Reputation: 215
I was developing my project on ubuntu (clion ide) but I changed distribution to xubuntu and cloned the same repository to it. Unfortunately, each image which I include in project generate this runtime error:
Failed to load image "image.png". Reason: Unable to open file
SFML is installed correctly because I checked it with standard program from SFML Site. I didn't have that problem on ubuntu.
I think that there is a problem with permissions of files. So I create sample project (as below), added player.png and I get the same error. So I use that command in terminal:
chmod a+w player.png
It doesn't solve a problem. I am new in linux so maybe there is something more to do, but I don't know. I also tried different ways from this site and SFML forum but it doesn't helps me.
I also tried to load other images, doesn't work too.
There is sample code which I have created to find problem. It is only modified sample from SFML Site.
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(400, 400), "SFML works!");
sf::Texture t;
t.loadFromFile("player.png");
sf::Sprite sprite;
sprite.setTexture(t);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(sprite);
window.display();
}
return 0;
}
What is interesting,
t.loadFromFile("../player.png");
solved the problem.
By default, sfml expected the image to be in cmake-build-debug
folder...
How to add default directory to my project, not to cmake folder?
Upvotes: 2
Views: 3413
Reputation: 259
You are looking for an option to change your current working directory. This can be done either using CLion or CMake.
Take a look at this question where you can find answers which describe both ways.
Upvotes: 3