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

Author Topic: Problems using image.LoadFromFile  (Read 2939 times)

0 Members and 1 Guest are viewing this topic.

paladin

  • Newbie
  • *
  • Posts: 2
    • View Profile
Problems using image.LoadFromFile
« on: November 24, 2008, 01:44:41 pm »
Hi at all,
I'm new to SFML and trying to make a small Pong game with it.

There is only one problem:
I try to load an Image this way:
Code: [Select]
sf::Image image;
if(!image.LoadFromFile("test.png"))
   return EXIT_FAILURE;

But LoadFromFile always returns false and the program exits with
Failed to load image "test.png". Reason: can't fopen

Now I tried
Code: [Select]
if(!image.LoadFromFile("/test.png"))
if(!image.LoadFromFile("./test.png"))

but this doesn't work, too.
The picture is definitely in the same folder as the exe.

Finally I tried this:
Code: [Select]
sf::Image image;
if(!image.LoadFromFile("C:/test/test.png"))
   return EXIT_FAILURE;

So an absolute path works, but not a relative path.

The samples and the tutorials use relative paths and I could not find a solution to this problem in the forum and using google.
Now I would like to ask if this is a "bug" or a "feature" :wink:.

PS: Sorry for bad English, but I'm German and not very good in languages.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problems using image.LoadFromFile
« Reply #1 on: November 24, 2008, 01:55:46 pm »
There's no bug, it's just that your working directory is not the one you think it is. How do you launch your executable ?
Laurent Gomila - SFML developer

Beaker

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • http://corvuscorone.net/
Problems using image.LoadFromFile
« Reply #2 on: November 24, 2008, 01:57:22 pm »
Are you using Visual Studio? If so, it tends not to set the paths correctly when debugging. Try setting the "working directory" in the project properties. If its not Visual Studio then sorry, I can't help, but I'm sure someone else can  :)

paladin

  • Newbie
  • *
  • Posts: 2
    • View Profile
Problems using image.LoadFromFile
« Reply #3 on: November 24, 2008, 02:00:10 pm »
I launch it using the Run button of CodeBlocks, but I will try starting the exe directly.

/e: Just tested and it works perfect  :D  :D  Thank you for your help.

 

anything