SFML community forums
Help => Graphics => Topic started by: lorence30 on April 15, 2015, 10:36:11 pm
-
can someone take a look at the picture below?
why im getting that error?
the image is already at the working directory
this is the code
if(!texture.loadFromFile("airplane.jpeg");
{
std::cout <<"error";
}
-
Just because the image file is in the same directory as your executable does not mean that it is in the current working directory when that executable is launched.
The current working dir can be set by another application that launches yours (like your IDE or the Windows cmd shell). Unless you explicitly change the cwd at runtime to be the same as the dir holding your executable you cannot make such assumptions.
If you want to be completely independent of where your app is launched from when loading resources, then obtain the path to your executable at runtime (http://stackoverflow.com/questions/1023306/finding-current-executables-path-without-proc-self-exe) and load all resources relative to that path.
-
In Visual Studio, the working directory can be set as follows:
Project Properties > Configuration Properties > Debugging > Working Directory
-
Also make sure you use the correct file extension / name. (jpeg instead of jpg for example)
And don't put a ; after your if.
-
And don't put a ; after your if.
This. You terminated the IF prematurely, so std::cout <<"error";
will always execute.
As for the loading problem, go into your "Debug" directory and see if the JPG is there with your EXE.
Make sure the file name is correct - JPG or JPEG, and finally, make sure that the image is valid and it loads properly in editors and viewers.
-
"Just because the image file is in the same directory as your executable does not mean that it is in the current working directory when that executable is launched."
if you create a project, the working directory is where your project file is by default. or im wrong?
i have another problem
the first picture , it is loading the file succesfully and displays it
but theres a warning in my console window
in the second picture, it looks like my sfml doesnt support jpeg file, im using sfml 2.2 of nightly's build
-
instead of jpeg, it should be jpg (no 'e')
hence,
if(!texture.loadFromFile("airplane.jpeg");
{
std::cout <<"error";
}
should be
if(!texture.loadFromFile("airplane.jpg");
{
std::cout <<"error";
}