Archived

This topic is now archived and is closed to further replies.

MetroidHunter

Quick question about using JPEG files withSDL

Recommended Posts

Don''t know about loading JPEG files with SDL.
About your error: I had that when I forgot to put a ";" after a class declaration.

  
class ClassA{
//stuff

}; //<---That one

Share this post


Link to post
Share on other sites
By itself SDL can only load a surface from a BMP, if you want to load a JPEG you will have to either write your own function or use another library that works with SDL.
One such library is SDL_Image this supports tons of different formats including JPEG’s.

Cheers.

Share this post


Link to post
Share on other sites
Well, it compiles now, but it won''t run. I''m getting this error:

  
main.obj : error LNK2001: unresolved external symbol _IMG_Load
Debug/game.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Is there something I need to do with my project settings to get SDL_Image to work properly? BTW, I''m using Visual C++ 6.0

Share this post


Link to post
Share on other sites
Yes, as well as #including SDL_image.h you need to link to SDL_image.lib, I don’t know how to do that in VC++ because I don’t use it.
Don’t forget you will probably also need access SDL_image and Jpeg dll’s at run time, they should probably be in your Windows\System or Windows\System32 folder.

Share this post


Link to post
Share on other sites
I linked the SDL_image.lib file, and put the following .dll files in my system directory: zlib, libpng1, jpeg, and SDL_image.
It builds the exe now, but all that happens it that a black screen comes up, then disappears. Did I forget something?

Share this post


Link to post
Share on other sites
Add this to the end of your program before the return statement:

    
SDL_Event event;
bool done = false;

while(!done)
{
while(SDL_PollEvent(&event)
{
if(event.type == SDL_QUIT)
{
done = true;
}
if(event.key.keysym.sym = SDL_ESCAPE)
{
done = true;
}
}
}

what this does is that it will loop until either you press the X in the window - SDL_QUIT, or press escape while the program is running. Doing either will exit the program but this way you''ll at least get time to see something. [/source]

Share this post


Link to post
Share on other sites
That means something bad has happened and your SDL application has terminated abnormally.

Somewhere along the line you have probably accessed some memory you shouldn’t have, debug and step through your program to find out where your bug is.

Share this post


Link to post
Share on other sites