Jump to content
  • Advertisement

Archived

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

MetroidHunter

Quick question about using JPEG files withSDL

This topic is 5599 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

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
Advertisement
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
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
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
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!