the problem is that you are creating a texture inside this function
sf::Texture loadImage(std::string fileName) {
sf::Texture texture;
if (!texture.loadFromFile(fileName)) {
std::cout << "failed to load image" + fileName << std::endl;
}
return texture;
}
when the function ends, the texture is destroyed.
why don't you just use
sf::Texture dirt;
dirt.loadFromFile("dirt.png");
instead of sf::Texture dirt = loadImage("dirt.png");
?
Is the image in the SFML folder?
I use this code:
sf::RectangleShape shape(sf::Vector2f(10.0f, 10.0f));
sf::Texture texture;
texture.loadFromFile("imageName.png");