Sign in to follow this  

SFML, Unable to open file

Recommended Posts

Im just running through some of the SFML tutorials on their website, and ran into an issue when running the sprite tutorial. It seems to be having issues loading the image. I know I have it in the right place, because if I move the image, the error says it cannot find the file. I am using visual studio 2008, on windows 7 x64. I have this example as a release build and I am using the release version dll files (sfml-graphics.dll, sfml-system.dll and sfml-window.dll). Here is my code:
// SFMLGraphics.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include <iostream>
#include <SFML/Graphics.hpp>

int _tmain(int argc, _TCHAR* argv[])
	sf::RenderWindow app(sf::VideoMode(800, 600, 32), "SFML Graphics");
	sf::Image image;
		std::cout << "Could not load sprite image\n";
		return EXIT_FAILURE;

	sf::Sprite sprite(image);
	sprite.SetColor(sf::Color(0, 255, 255, 128));
	sprite.SetPosition(200.f, 100.f);
	sprite.SetScale(2.0f, 2.0f);

		sf::Event e;
			if(e.Type == sf::Event::Closed)

		app.Clear(sf::Color(0, 0, 0));

I'm calling the system pause so I could see the error messages SFML outputs. Any ideas on what I might be doing wrong?

Share this post

Link to post
Share on other sites
I don't know if it's windows7 related. However, it's probably a matter of the relative path to the texture. Because you don't give a path to the texture, it's looking in several default places and, apparently, not finding it.

To see if that's the problem, use the full path to the texture:
"c:\\projects\\sfmlgraphics\\resource\\sprite.jpg" or whereever your texture is located.

If that's the problem, there are quite a few discussions on this site about setting up paths to resources. The favorite method involves calling GetModuleFileName() and deriving a path from that.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this