Archived

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

MetroidHunter

Quick question about using JPEG files withSDL

Recommended Posts

MetroidHunter    122
How can I load JPEG files for use in a game with SDL? I know how to load bitmaps, but I don''t know a statement that will work with other formats. Please help. Thanks in advance.

Share this post


Link to post
Share on other sites
MetroidHunter    122
also, what does this error mean? It occurs right after my include statements...

  
c:\game\main.cpp(18) : error C2143: syntax error : missing '';'' before ''PCH creation point''

Share this post


Link to post
Share on other sites
RizMan    146
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
KiwiMelon    122
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
MetroidHunter    122
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
KiwiMelon    122
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
Spudder    385
SDL_image library requires the SDL,jpeg and libpng .libs\.dlls, but all you need to link in is the SDL_image.lib file into your project.

Share this post


Link to post
Share on other sites
MetroidHunter    122
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
Spudder    385
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
MetroidHunter    122
I have that in my loop. The black screen comes and goes before I can hit escape. I did notice a stderr.txt file that said:

Fatal signal: Segmentation Fault (SDL Parachute Deployed)

What does that mean?

Share this post


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