SFML community forums

Help => General => Topic started by: prchakal on September 14, 2012, 11:21:34 am

Title: Resources like images are not found by Application
Post by: prchakal on September 14, 2012, 11:21:34 am
Hi,

Resources add not recognized by my Application here:
https://github.com/prsolucoes/sfml-cmake (https://github.com/prsolucoes/sfml-cmake)

The "images" are in the path "sfml-project.app/Contents/Resources/images" but i get error:

Quote
Failed to load image "images/robot1.png". Reason : Unable to open file

Can anyone help me?
Title: Re: Resources add not recognized by Application
Post by: eXpl0it3r on September 14, 2012, 12:23:21 pm
You have to specify the full relative path.
Thus when your application is in the path /myapp.exe and the resource is in /Contents/Resources/images/bla.png then you'll have to load the image with
.loadFromFile("Contents/Resources/images/bla.png")
Title: Re: Resources add not recognized by Application
Post by: Laurent on September 14, 2012, 01:02:40 pm
Quote
You have to specify the full relative path.
There's a specific handling of the working directory on OS X. I don't remember what it is, Hiura should be able to help :)
Title: Re: Resources add not recognized by Application
Post by: eXpl0it3r on September 14, 2012, 01:53:05 pm
There's a specific handling of the working directory on OS X. I don't remember what it is, Hiura should be able to help :)
Oh I didn't notice that he was referring to OS X... ;D
Title: Re: Resources add not recognized by Application
Post by: Hiura on September 14, 2012, 02:23:17 pm
Yeah, with Mac you have to think different, they said.  ;)

As stated in the introductory tutorial (http://www.sfml-dev.org/tutorials/2.0/start-osx.php), you have to use a special function to get the resource path, std::string resourcePath(void). If you use Xcode, then the function is imported into your project automatically by the SFML project wizard. But if you want to stay away from this IDE you can simply download these two files : ResourcePath.hpp (https://github.com/SFML/SFML/blob/master/tools/xcode/templates/SFML/SFML%20Application%20Base.xctemplate/ResourcePath.hpp) and ResourcePath.mm (https://github.com/SFML/SFML/blob/master/tools/xcode/templates/SFML/SFML%20Application%20Base.xctemplate/ResourcePath.mm).

The implementation is written in Objective-C. You should not have issue with cmake in theory. But if you do you can reimplement the function in C with CFBundle API (https://developer.apple.com/library/ios/#documentation/CoreFoundation/Reference/CFBundleRef/Reference/reference.html).
Title: Re: Resources like images are not found by Application
Post by: prchakal on September 14, 2012, 05:09:20 pm
Hi,

Problem solved and commited to repository.

Ty.