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

Author Topic: Loading png files in visual studio. Can't find the file  (Read 14470 times)

0 Members and 1 Guest are viewing this topic.

Darkying

  • Newbie
  • *
  • Posts: 2
    • View Profile
Loading png files in visual studio. Can't find the file
« on: July 14, 2012, 05:26:04 pm »
Hello,
I'm sure I'm making a stupid mistake somewhere, but I can't seem to load a image.png for the "Displaying a sprite" tutorial. I have SFML up and running (I can run some of the other tutorials, like the "Using render windows" tutorial). I'm working with SFML 1.6 and MVS 2008 in Windows 7 64 bits. The only change I've made to the code of the tutorial is putting the name of the image I'm using, instead of the default name the tutorial had.

 if (!Image.LoadFromFile("image.png"))

image.png is this image,  normal 32 bit png, weights 43kB, has nothing strange. And I've tried putting it in the output folder (where the .exe is generated), in the intermediate folder, in the project root, adding it to the "Resource Files" folder inside MVS. And still getting the "Failed to load image "image.png". Reason : Unable to open file" error when I run the example code from the tutorial.

I've tried in release and debug mode, linking the correct libraries in each case, in case it made a difference.

I've tried with a different png image.

Any ideas? Thank you for your time.
Cheers!

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Loading png files in visual studio. Can't find the file
« Reply #1 on: July 14, 2012, 06:05:59 pm »
This is a common issue when loading resources using a relative path. If you can check in your IDE where it runs your executable from you can find out where "image.png" should be located relative to that path. If that is not easily done, what I do is just copy image.png to every single folder in your project directory and see if that works. If it does, systematically delete them one by one and see when SFML complains again. It's your choice which method you choose :)
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Darkying

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Loading png files in visual studio. Can't find the file
« Reply #2 on: July 14, 2012, 08:59:25 pm »
Thank you for your tip. Of course the location was wrong, I should have seen that but I guess I was a bit dull today. I tried with an absolute path (got the inspiration from your reply):

And it worked, so now I knew it actually DID load the image, finding out where was was easy. For future reference, images for SFML in MVS projects are placed...

CORRECTLY
  • In the root directory of the project

INCORRECTLY
  • In the root directory of the solution
  • In the output directory
  • In the intermediate directory

mastodona7x

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Loading png files in visual studio. Can't find the file
« Reply #3 on: July 14, 2012, 10:16:39 pm »
Yeh got me first ever time I tried, now I have a folder for "images" "sfx" "fonts" etc etc in the root of each new project I make :)

 

anything