Loading GIF and other formats with SDL

Started by
8 comments, last by GenuineXP 18 years, 7 months ago
Hi. I'm learning how to use SDL and created a sprite class to handle loading and displaying images. At this point, my sprite class can load a Windows bitmap and blit it to a surface. To display animated sprites, the sprite class blits different parts or cells of a bitmap in order. I pretty sure this is a common approach, but I want to be able to load other formats into my sprite class like GIF images. Is there a way to do this with SDL? SDL_LoadBMP() seems to be the only function which loads an image file onto a surface. Thanks in advance. :-)
Advertisement
Yes, SDL_Image, take a look at this recent thread.
Thanks for the help!

Unfortunately, I'm having trouble getting the library to work. :-( I think it'd be easier if someone could explain to me just how to install the library and get it to work with my program rather than listing the steps I took. :-P

Thanks again! :-)

By the way, I'm using Code::Blocks and the GNU GCC Compiler. I downloaded the Win32 source and binaries of the SDL_image library.
In that case, you will want to look at the last post on that thread. It says Dev-Cpp, but it's the same for Code::Blocks with the GCC complier.

As for where to get SDL_Image for GCC, I wasn't sure where you could get it with the necessary files, so I just ripped apart the DevPak and put the files in a zip here. I think that should work fine, but no guarantees. I think I got all the files transferred.

All you need to do to use it is link in the SDL_Image.a file (place it with the SDL.a file you have), include the SDL_Image.h header file (also put this with your SDL.h file) and place the .DLL's either in your projects folder or your Windows System32 or equivilant directory.
Hmm... I did that, but when I attempt to use IMG_Load() I get the compiler error "undefined reference to 'IMG_Load'".

I've included SDL_Image.h in my main.cpp file and linked to SDL_Image.a.

Any ideas? :-(
If you are getting a "compiler error", then check to make sure the SDL_Image.h file is in the same folder as your SDL.h file and that path to that directory is in the include file directories (i.e. make sure your SDL.h can also be found)

If you are getting a "linker error", then check to make sure you linked in SDL_Image.a correctly, either by using -lSDL_Image or by simply choosing SDL_Image.a though the library file selector. (also make sure the SDL.a file can be found)

Other than that, I'm not a Code::Blocks user, so if it still doesn't work, maybe someone that uses that IDE can help you out. Good luck!
I'm linking to SDL_image.a without problems. My program runs just fine without adding SDL_Image to the project, so I know it's finding all the standard SDL files it needs (headers and libraries).

I'm still getting compiler errors. However, when I remove the preprocessor command to include SDL_Image.h the message changes from "undefined reference to 'IMG_Load'" to "'IMG_Load' undeclared (first use this function)".

Thanks for all the help so far, Drew_Benton. :-)
Ah, I finally got it to work! I had to link to SDL_image.dll as well as SDL_image.a!

Now I have a new problem though! I'm loading a GIF image, but how do I display it correctly? (How do I display the animation?)
Quote:Original post by GenuineXP
Ah, I finally got it to work! I had to link to SDL_image.dll as well as SDL_image.a!


What the heck?! Maybe someone can explain that one to me.

Quote:Now I have a new problem though! I'm loading a GIF image, but how do I display it correctly? (How do I display the animation?)


Sorry for the bad news, but you can't. Take a look at this thread for more information on this topic. But that does not mean you couldn't perhaps write your own GIF animating class!
Ah, I see. Welp, thanks for all the help!

This topic is closed to new replies.

Advertisement