SFML community forums

Help => Graphics => Topic started by: maninboots on August 20, 2007, 09:02:19 pm

Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post 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
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: Laurent on August 20, 2007, 09:49:43 pm
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 ?
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: maninboots on August 20, 2007, 10:53:21 pm
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:

Code: [Select]

if (!Image.LoadFromFile("sprite.tga"))
        return EXIT_FAILURE;


It compiles without errors.. i've got 2 warnings tho'

Code: [Select]

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
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: lubos on August 20, 2007, 11:06:37 pm
Quote from: "maninboots"
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:
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: maninboots on August 20, 2007, 11:19:40 pm
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?
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: lubos on August 20, 2007, 11:23:30 pm
hmm just to be sure, app works normally when u will remove all image loads & draws calls?
edit: ah, yes just read the error  .. :?
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: maninboots on August 20, 2007, 11:47:39 pm
Yeah, it returns the error "Failed to load image from file" in the console.
So not in the builder/compiler/linker.
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: zarka on August 20, 2007, 11:55:12 pm
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.
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: maninboots on August 21, 2007, 12:34:10 am
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.
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: Alp on August 21, 2007, 01:53:56 am
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.
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: s_p_oneil on August 21, 2007, 02:10:10 am
Did you make sure to put the DLL's in extlibs\bin in your PATH somewhere?
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: maninboots on August 21, 2007, 02:11:57 am
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!
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: maninboots on August 21, 2007, 02:19:26 am
Quote from: "s_p_oneil"
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 :(
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: Laurent on August 21, 2007, 08:31:57 am
This looks weird. Did you try to open the SFML solution (SFML-1.0\vc2005\SFML.sln), recompile everything and run the samples ?
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: lubos on August 21, 2007, 10:09:20 am
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..  :?
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: maninboots on August 21, 2007, 11:47:16 am
Quote
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
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: Laurent on August 21, 2007, 11:59:21 am
I opened / compiled / run you project without any error. The sprite is loaded and displayed correctly.
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: maninboots on August 21, 2007, 12:06:56 pm
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 ! : :)
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: Laurent on August 21, 2007, 12:14:36 pm
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).
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: maninboots on August 21, 2007, 05:59:57 pm
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..
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: Mindiell on August 21, 2007, 06:04:05 pm
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:
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: Laurent on August 21, 2007, 07:09:41 pm
Quote
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)..
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: maninboots on August 21, 2007, 07:33:18 pm
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!
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: lubos on August 21, 2007, 07:44:48 pm
Quote from: "maninboots"

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..
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: maninboots on August 21, 2007, 08:18:42 pm
Quote from: "lubos"
Quote from: "maninboots"

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
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: Laurent on August 21, 2007, 08:23:18 pm
Quote
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).

Quote
And another thing, can I load images with alpha channels ?

Yes, alpha channels are properly loaded ;)

Quote
Photoshop doesn't support alpha channels in TGA

Really ? If so, I guess you have an old version of Photoshop.

Quote
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.
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: maninboots on August 21, 2007, 08:39:56 pm
Quote
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

Quote
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.

Quote
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.

Quote
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
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: Laurent on August 21, 2007, 08:47:22 pm
Quote
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 ?
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: maninboots on August 21, 2007, 09:46:52 pm
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
Title: Image.LoadFromFile("sprite.tga") Won't load the im
Post by: Laurent on August 22, 2007, 08:21:20 am
Quote
Edit: But I do get 20 Warnings .. hmm

Which ones ? ;)
Title: Re: Image.LoadFromFile("sprite.tga") Won't load th
Post by: gigetto on September 08, 2007, 10:24:44 pm
Quote from: "maninboots"
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?
Title: I know how to resolve on of your warnings
Post by: Pwndja on September 17, 2007, 03:37:09 am
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