#### Archived

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

# Quick question about using JPEG files withSDL

## Recommended Posts

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 on other sites
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 on other sites
RizMan    146
About your error: I had that when I forgot to put a ";" after a class declaration.

  class ClassA{//stuff}; //<---That one

##### 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 on other sites
Thanks for all your help. Let me see if I can get this comiled. Later

##### 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_LoadDebug/game.exe : fatal error LNK1120: 1 unresolved externalsError 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 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 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 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 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 on other sites
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?