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

Author Topic: [SOLVED] texture.loadFromFile doesn't work  (Read 9179 times)

0 Members and 1 Guest are viewing this topic.

heu

  • Newbie
  • *
  • Posts: 2
    • View Profile
[SOLVED] texture.loadFromFile doesn't work
« on: February 03, 2015, 12:47:37 am »
So I simply want to load a texture and apply it to a sprite just like it is done in the tutorials.

I am using SFML 2.2, Visual Studio Express 2013.

The problem is that texture.loadFromFile() doesn't work at all for me. I have tried to place my file in a thousand different places and I always get the same result. Finally I decided to use the full path, same problem. I also tried different formats: PNG, GIF, JPG, BMP. I also tried to save them with different software: Photoshop, GIMP, paint. Nothing helps. The only error message displayed is:

Failed to load image "

Exactly like that, only one double quote at the end.

Help!

Here's the minimal code I tried.

#include <SFML/Graphics.hpp>

int main()
{
   sf::Texture texture;
   if (!texture.loadFromFile("C:\\temp.png"))
      return 1;

   return 0;
}
 


« Last Edit: February 03, 2015, 05:23:21 pm by heu »

GetOutOfBox

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: texture.loadFromFile doesn't work
« Reply #1 on: February 03, 2015, 03:25:03 am »
That code works for me. That means the code is fine, so all I can think of is it's either:

A) The specific image, though you seem to have troubleshooted for this. Have you tried a completely different image just to be sure? Try creating a new image in GIMP that is just solid black, 40x40, and in the RGB mode format.

One thing I've run into is that 8-bit PNGs are not supported, although they are unusual. However if the issue is related to a property of the image, you'll discover this if a completely new PNG made to standard works fine.

B) A problem with the DLLs. Check all dependencies are up to date, recopy all of the binaries to your project and .exe folder.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10823
    • View Profile
    • development blog
    • Email
Re: texture.loadFromFile doesn't work
« Reply #2 on: February 03, 2015, 09:47:22 am »
Also make sure to always use forward slashes in paths. It works fine on Windows as well.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

heu

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: texture.loadFromFile doesn't work
« Reply #3 on: February 03, 2015, 05:23:10 pm »
Thanks for the answers!

I managed to figure out what was wrong.

I was running the code with a debug configuration. Switching to release suddenly got it working.

It turns out I had set the release .libs to the debug linker options under Properties | Linker | Additional dependencies. Just by adding -d to the file names did the trick!

Everything works fine now! Thanks again.

niceguy4704

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: [SOLVED] texture.loadFromFile doesn't work
« Reply #4 on: December 27, 2016, 03:29:07 pm »
I started learning SFML this weekend. I reached this part of the Getting Started tutorials and hit an "unhandled exception" whether the address to the file was correct or not (if not, it was supposed to say file not found. but didnt in my case). after googling the problem and no other suggestions working, I found this one and FINALLY it worked! thank you!


SFML 2.4.1
Visual Studio 2015
C++

 

anything