Sign in to follow this  

Loading GIF and other formats with SDL

This topic is 4482 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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. :-)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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? :-(

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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. :-)

Share this post


Link to post
Share on other sites
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?)

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

This topic is 4482 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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