Jump to content
  • Advertisement
Sign in to follow this  
noobsiabot

SDL Load_BMP help!

This topic is 3267 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 everybody, I'm new to game / graphics programming and have started to dabble with SDL and OpenGL. So to start off with a very simple program I'm trying to load a BMP with SDL_LoadBMP (windows with Visual Studio 2008) I'm includiing the full source here (very short :) ) #include <sdl/sdl.h> #include <stdio.h> SDL_Surface* screen = NULL; SDL_Surface* img = NULL; SDL_Event myevent; bool quit=false; int main(int argc, char *argv[]) { atexit(SDL_Quit); if (SDL_Init(SDL_INIT_VIDEO) == -1) {printf("SDL init failed"); exit(1);} img = SDL_LoadBMP("woods.bmp"); //simple 640x480x24bpp bmp if (!img) { printf("Couldn't load bmp \n",SDL_GetError()); exit(1); }; //and just here my prgram crashes with "couldn't load bmp" SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); screen = SDL_SetVideoMode(1024,768,32,SDL_OPENGL | SDL_FULLSCREEN); if (screen == NULL) {fprintf(stderr,"Video mode failed"); exit(1); } while (!quit) { SDL_PollEvent(&myevent); switch (myevent.type) {case SDL_KEYDOWN: switch (myevent.key.keysym.sym) {case SDLK_ESCAPE : quit = true; break; }; break; }; }; SDL_FreeSurface(img); SDL_Quit(); } What am I doing wrong? I've looked at plenty of examples but cannot spot the mistake.

Share this post


Link to post
Share on other sites
Advertisement
It's possible that it can't find the file. You can check for that using this function:


bool exists(const char *fileName) {
FILE *file = fopen(fileName, "r");
if (!file)
return false;

fclose(file);
return true;
}

// Inside main()
if (!exists("woods.bmp"))
printf("Can't find file: woods.bmp");



Also, try calling SDL_LoadBMP after the call to SDL_SetVideoMode (although I'm not sure if that will make any difference).

Share this post


Link to post
Share on other sites
Thanx for the reply, and you were right: it doesn't find the file! But I have put a copy of it in the same folder where the EXE resides:

C:\...\My Documents\Visual Studio 2008\Projects\sdl basic\Debug

and also, a copy in the specific project's folder:

C:\...\My Documents\Visual Studio 2008\Projects\sdl basic

Must I put it anywhere else?

Share this post


Link to post
Share on other sites
To prevent this from happening, go to Project Properties -> General, and in the Output Directory field, enter the project's directory. This will cause the exe to be created in the project's directory.

Do the same in Project Properties -> Debugging in the Working Directory field. This will save you some headaches when debugging.

Share this post


Link to post
Share on other sites
Thanx I did what you said and copied the bmp into those directories... now all I have to do is get it on screen... :)

Thanks four your help.

Share this post


Link to post
Share on other sites
Quote:
Original post by noobsiabot
I did what you said and copied the bmp into those directories


I meant that you should write the same directory in both those locations (Output Directory and Working Directory), preferably the project directory.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!