Search code examples
c++imagesfml

Problems with SFML loadFromFile command


I am trying to get a graphical representation of a chess-board with SFML 2.0. The problem is that I simply cannot load a texture, the command loadFromFile does not work and I don't know why. I already searched the web, also here in Stack Overflow but I did not find a solution.

What I did right now:

  • Setting all the dependencies for includes and libraries, .dll's and .libs
  • Changing text format from unicode to multibyte.
  • Copying the .dll's into the working folder (there was an error that visual studio couldnt find the dlls even though I linked them in the project)
  • Using the whole path for the image file
  • using the LoadFile-command with 2 arguments (even though the second one is optional I guess)
  • Changing runtime library from MDd to MD (trying to get it work in release mode)
  • Not linking all libraries, but only the ones with a ....-d.lib ending (as supposed in another Stack Overflow thread)

I use Windows 7, Visual Studio Version 15.3.3

This is my code:

#include <SFML/Graphics.hpp>
#include <time.h>
#include <iostream>

int main() {

    sf::RenderWindow window(sf::VideoMode(437, 437), "MattseChess!");
        
    sf::Texture t1;
    if (!t1.loadFromFile("C:/Users/Mattse/source/repos/Chess/Chess/images/figures.png")) {    
        std::cout << "Error loading texture" << std::endl;        
    }

    return 0;
}

What shall I try out next?


Solution

  • Problem fixed, it was in fact the case that I forgot to delete one library in the linker->input settings. I only have the ones with a -d ending now, even the ones which have NO -d equivalent got deleted.

    List of linked libraries:

    sfml-audio-d.lib
    sfml-graphics-d.lib
    sfml-main-d.lib
    sfml-network-d.lib
    sfml-network-s-d.lib
    sfml-system-d.lib
    sfml-system-s-d.lib
    sfml-window-d.lib
    sfml-window-s-d.lib