SFML community forums
Help => Graphics => Topic started by: maninboots on August 20, 2007, 09:02:19 pm
-
Hello! I'm new to SFML but so far it looks great, except that I can't get my images to load properly.
The program Builds just fine but it always returns the "Failed to load image from file" error.
I've tried TGAs, JPGs, PNGs, even 1bit BITMAPS, but nothing works.
I'm keeping my files in: [ \Visual Studio 2005\Projects\{name}\debug\ ], and that should be right, right ? :P
I've even tried to change the image line to "C:\\sprite.tga" and moving the picture to the root map but it doesn't work.
I've tried using my own code and the tutorial code. Please help!
Regards Mattias from Sweden ! :D
-
I would say this is a working directory problem (try to run the executable not from the IDE), but as you tried an absolute path... Can you give a short sample code that reproduces the problem ? What's your OS ?
-
I've tried using the "Displaying a Sprite" tutorial source file, and it's the same errors there. I guess it's this that calls the error:
if (!Image.LoadFromFile("sprite.tga"))
return EXIT_FAILURE;
It compiles without errors.. i've got 2 warnings tho'
Warning 1 warning LNK4075: ignoring '/INCREMENTAL' due to '/LTCG' specification test01SFML
Warning 2 warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library test01SFML
But the warnings only occurs when I include the SFML/Window.hpp header, and that is not needed in the tutorial so I guess it has nothing to do with this problem.
As you said I've tried the absolute path and I've tested to run the executable.
My OS is 32bit Windows XP Pro and I use MS Visual Studio 2005.
Thanks
-
I've tried using the "Displaying a Sprite" tutorial
But the warnings only occurs when I include the SFML/Window.hpp header, and that is not needed in the tutorial so I guess it has nothing to do with this problem.
Thanks
hm i think graphics.hpp includes also window.hpp, cause the sfRenderWindow inheirt's from sfWindow
can't help on the warnings much though :oops:
-
Ok, thats weird. The warnings doesn't matter - I just wanna get my sprites to show on the screen :)
Could someone with Visual Studio 2005 like make a solution with sprites and upload it somewhere, so I could try to compile it and see if it works?
-
hmm just to be sure, app works normally when u will remove all image loads & draws calls?
edit: ah, yes just read the error .. :?
-
Yeah, it returns the error "Failed to load image from file" in the console.
So not in the builder/compiler/linker.
-
have you tried putting your images in the same folder as your .sln/.vcproj file(s) ?. this is the default working directories in vc2005.
To change working directory in vc2005, right click on your project and choose properties then under debugging tab you can set working directory.
-
Didn't work. Already had my image file both in the directory where the .sln is and the debug.
I even tried to copy the image in every directory of my project's directory, didn't work either.
It can't be that the image isn't located. It must be something in the
sfImage::LoadFromFile() Function.
Something in that function goes wrong and returns the error.
When I debug it goes through alot of files but you never see anything about the LoadFromFile() Function, and nothing about the string "Failed to load image from file".
So I can't locate the error.
-
The images must be in the same directory as your executable file.
The easiest way is to load with the "./" path, like LoadFromFile("./something.png"), putting something.png in the debug binary directory, or in a subdir data, and then loading "./data/something.png".
See samples for more precisions.
-
Did you make sure to put the DLL's in extlibs\bin in your PATH somewhere?
-
doesn't work either.. getting mad at this error!
I'm starting to think that this problem is not within the code, it's propably some settings or linking I've done wrong, or mayby I installed SFML wrong.
But then again, alot of the other tutorials work.
I've got this in the Linker-Input:
sfml-main.lib sfml-window.lib sfml-system.lib sfml-graphics.lib
that should be alright, and I'm creating an Empty Win32 Console Application at the start, that's right, right ?
Getting CRAZED at this error!
Thanks for all the help though!
Edit: But the weird thing is that no one else got this problem!
-
Did you make sure to put the DLL's in extlibs\bin in your PATH somewhere?
Well I did get an error first that said something like "Can't find DevIL.dll" .
So I moved that to the debug folder and the error message dissapeared so, I think I did!
Edit: Anyways, got all the DLL files in the debug and the directory where the .sln is so, can't be the dlls :(
-
This looks weird. Did you try to open the SFML solution (SFML-1.0\vc2005\SFML.sln), recompile everything and run the samples ?
-
maybe you can send your project files to someone that have visual c++ and see if it will works for him..my ide can import vc projects, however no vc compiler here on linux.. :?
-
maybe you can send your project files to someone that have visual c++ and see if it will works for him..my ide can import vc projects, however no vc compiler here on linux.. Confused
Ok, here's my project folder:
http://www.hakucenter.com/spriteTest.zip
-
I opened / compiled / run you project without any error. The sprite is loaded and displayed correctly.
-
Ok, now thats really weird. Did you change anything, anything at all ?
If not, I'll try and reinstall Visual Studio and SFML.
Thanks for the help ! : :)
-
I just added the paths for SFML headers and libs, and linked with the debug versions of the libraries (but that shouldn't change anything).
-
How exactly did you do that ? I'm very new to C++ (been learning VB.Net in one year and I switched to C++ like 5 days ago).
Guess it's something basic that I've forgotten..
-
Same problem here with code::blocks. My source is in a directory, and I got a bin/debug directory for my exe.
This path is working under EDI :
=> ./bin/debug/datas/image.gif : yes !
But it's no more working out of the EDI. So I think you just have to get a good "work path", like I'll try to do tonight with Code::Blocks :wink:
-
Guess it's something basic that I've forgotten..
As your program compiles and runs, I think it's not related to the project setup. It's more a problem of working directory. Did you try to put your program and the image in the same directroy, and run it directly from there ?
You can also try to compile and run in release mode (to make sure the problem is not coming from the use of release libs in debug mode)..
-
Oh my god, I feel so stupid.. it worked in release mode ? How ?
Can I get it to work in debug mode also ?
Thanks for all the help !! :D
Edit: Well I can debug in release mode so I guess this is solved !! :D
THANKS! Very good support.. thumbs up for SFML and Laurent!
-
Edit: Well I can debug in release mode so I guess this is solved !! :D
debugging symbols shouldnt be produced in release mode, maybe it can break your program but it shouldnt be able to see some really detailed info..
-
Edit: Well I can debug in release mode so I guess this is solved !! :D
debugging symbols shouldnt be produced in release mode, maybe it can break your program but it shouldnt be able to see some really detailed info..
Ok, so how do I fix it so I can run it in Debug Mode ?
And another thing, can I load images with alpha channels ?
Photoshop doesn't support alpha channels in TGA so I tried to create an alpha with "TGA Tool", but I can't load that image in the program.
What's the use of sprites (in games) if you can't have an alpha channel ?
Is there a way to like - assign a special color to be the Alpha Channel Color (Like DirectX?),
so that I can output the image with like an Pink background and then let SFML make it transparent ?
Thanks
-
Ok, so how do I fix it so I can run it in Debug Mode ?
Just link with sfml-graphics-d.lib instead of sfml-graphics.lib (the same for other libraries -- sfml-window-d.lib and sfml-system-d.lib).
And another thing, can I load images with alpha channels ?
Yes, alpha channels are properly loaded ;)
Photoshop doesn't support alpha channels in TGA
Really ? If so, I guess you have an old version of Photoshop.
Is there a way to like - assign a special color to be the Alpha Channel Color (Like DirectX?),
so that I can output the image with like an Pink background and then let SFML make it transparent ?
As I said you can load the alpha channel directly, but if you want to make a particular color transparent after loading the image in your program, you can use the sfImage::CreateMaskFromColor function.
-
Just link with sfml-graphics-d.lib instead of sfml-graphics.lib (the same for other libraries -- sfml-window-d.lib and sfml-system-d.lib).
Ok Thanks ! :D
Photoshop doesn't support alpha channels in TGA
Sorry, I meant that Photoshop doesn't support automatic alpha channel (like for GIF and PNG), you have to make your own alpha channel in the channel window.
Yes, alpha channels are properly loaded Wink
Really ? I did make an alpha channel in photoshop and then saved it as an TGA, it didn't load. Then I tried with TGA Tool and made an alpha channel , didn't load either.
As I said you can load the alpha channel directly, but if you want to make a particular color transparent after loading the image in your program, you can use the sfImage::CreateMaskFromColor function.
Ok, I'll use that function if nothing else works!
Thanks
-
Really ? I did make an alpha channel in photoshop and then saved it as an TGA, it didn't load. Then I tried with TGA Tool and made an alpha channel , didn't load either.
What do you mean ? The loading caused an error ? Your sprite is showing but with no transparency ? Did you check some pixels to see if their alpha value are correct ?
-
It seems I got it to work, all of a sudden it takes .jpg .png everything, with or without alpha channels. I have no idéa of what I did, but it works!
Finally, I can start creating stuff.
Thanks! I'll be back sometime with more errors, I can feel it :) :D
Edit: But I do get 20 Warnings .. hmm
-
Edit: But I do get 20 Warnings .. hmm
Which ones ? ;)
-
Hello! I'm new to SFML but so far it looks great, except that I can't get my images to load properly.
The program Builds just fine but it always returns the "Failed to load image from file" error.
I get the same error if I use release libraries in debug mode. To be honest it should not make a difference, but it does.
My problem is that I cannot build the release vesion of my app because I get:
fatal error C1047: The object or library file 'D:\SFML-1.0\lib\vc2005\static\sfml-window.lib' was created with an older compiler than other objects; rebuild old objects and libraries
What should I do?
-
this warning:
Warning 2 warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library test01SFML
if you go to this web site there is a table of libs which you can enter in one of your properties menus to turn off some libs which conflict with sfml libs..
http://www.stanford.edu/~yljiang/pages/GPRS%20Linking%20Warning.htm
copy the apropriate line of libs and paste them into ignore specific libs, which can be found in project->properties->linker->input