Ashley Davies
Ashley Davies

Reputation: 1903

SFML not loading image (Possibly due to placing in wrong place?)

I'm not sure whether I'm doing something stupid or visual studio is doing something wrong.

I've never really used C++ with VS before, but I managed to get SFML working, and now I cannot load images.

This is how I put the image in the project:

Image

However when I write:

if (!tileTexture.loadFromFile("ConceptTile.png"))
    return EXIT_FAILURE;

It returns EXIT_FAILURE.

Can anyone give an answer to why this isn't working?

If it helps that png file isn't appearing anywhere in the debug directories, just dlls, exes, and pdbs.

I've looked online to try to find out where I am supposed to put images but I can't find any articles or help no matter what keywords I type.

Upvotes: 0

Views: 2216

Answers (2)

Open Windows Explorer and move to the folder that contains the C++ files and paste the image there and it shall work or make a folder and change the directory in code, for example, if you name the folder images :

(!tileTexture.loadFromFile("images/ConceptTile.png"))
return EXIT_FAILURE;

and it shall work.

Upvotes: 0

Mario
Mario

Reputation: 36537

Make sure you change the file properties within the project to copy it to the output directory. By default (and without further paths given in the string) SFML should look for the file in your working directory. You don't have to add image files to your project, if you ensure they're at the right place. Also make sure to not include them as resources (as SFML won't be able to load them without some additional code).

Upvotes: 1

Related Questions