Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Resources like images are not found by Application  (Read 5423 times)

0 Members and 1 Guest are viewing this topic.

prchakal

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Resources like images are not found by Application
« on: September 14, 2012, 11:21:34 am »
Hi,

Resources add not recognized by my Application here:
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?
« Last Edit: September 14, 2012, 02:29:05 pm by prchakal »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10936
    • View Profile
    • development blog
    • Email
Re: Resources add not recognized by Application
« Reply #1 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")
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Resources add not recognized by Application
« Reply #2 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 :)
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10936
    • View Profile
    • development blog
    • Email
Re: Resources add not recognized by Application
« Reply #3 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
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Resources add not recognized by Application
« Reply #4 on: September 14, 2012, 02:23:17 pm »
Yeah, with Mac you have to think different, they said.  ;)

As stated in the introductory tutorial, 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 and 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.
SFML / OS X developer

prchakal

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Resources like images are not found by Application
« Reply #5 on: September 14, 2012, 05:09:20 pm »
Hi,

Problem solved and commited to repository.

Ty.

 

anything