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

Author Topic: [50% SOLVED]name.loadFromFile("pic.png") does not load the picture  (Read 1725 times)

0 Members and 1 Guest are viewing this topic.

Jigsik

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Hello,

I am dealing with this problem. I followed one tutorial on youtube and write this in code.

sf::Texture pTexture;
sf::Sprite PlayerImage;
if (!pTexture.loadFromFile("player1.png"))
                std::cout << "Error could not load player image" << std::endl;

And I can compile it without problems, run it and then I got my output when it couldnt load. I dont know what to do. I use Visual Studio 2013 and SFML 2.1. I have the picture at the same directory where my main is. I am new to SFML and I already tried a Joystick, Keyboard and mouse fucktions, to draw a cycrle etc. And this is the first thing that doesnt work..

Thanks for replies.
« Last Edit: July 06, 2014, 05:33:39 pm by Jigsik »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: name.loadFromFile("pic.png") does not load the picture
« Reply #1 on: July 06, 2014, 03:28:19 pm »
Assuming you've made sure the .png really is in the directory you think it is, the typical reason for this is IDEs using a different working directory from what you're expecting.  Try putting the file in some other places in the project (I think the Debug and Release folders are likely suspects).

Jigsik

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: name.loadFromFile("pic.png") does not load the picture
« Reply #2 on: July 06, 2014, 03:36:21 pm »
Thanks for reply!

I have already tried that. I read on one forum about someone who had the same problem, but he got problem with the project properties (badly wrote the libraries), but I think that would not be my problem when I already draw the cycrle and its the same library.

For now I am just debugging so I have just the debug folder. And before I forget, I have a 64bit and learning from tutorial on SFML 2.0 (if it helps)

Thanks one more time.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: name.loadFromFile("pic.png") does not load the picture
« Reply #3 on: July 06, 2014, 05:08:15 pm »
Quote
I have already tried that. I read on one forum about someone who had the same problem, but he got problem with the project properties (badly wrote the libraries), but I think that would not be my problem when I already draw the cycrle and its the same library.

None of this involves loading a external file from a relative filepath, so it doesn't prove anything.  The working directory is probably somewhere you haven't tried yet.

If you can't find the correct location by guessing, try things like https://stackoverflow.com/questions/143174/how-do-i-get-the-directory-that-a-program-is-running-from

Jigsik

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: name.loadFromFile("pic.png") does not load the picture
« Reply #4 on: July 06, 2014, 05:33:00 pm »
Hello one more time.

Thanks for your answers. I was playing with everything I think I could. And I tried to Compile it not in the Debug mode, but in the Release mode and it works (ofc. I copy the picture into the Release directory). But I don't know why it does not work in the Debug mode.. I tried every single directory in my project directory and none of them is the directory when the program for debugging is.. (or there is another problem..)

If someone can figure out what it should (or can) be. I will be happy. But I can stand with this for a while :).

Thanks a lot guys.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: [50% SOLVED]name.loadFromFile("pic.png") does not load the picture
« Reply #5 on: July 06, 2014, 05:36:33 pm »
Why don't you simply print out what it is?

  std::cout << "CWD is: " << getcwd() << std::endl;

or similar.
Then you don't need to guess.