Jump to content
  • Advertisement
Sign in to follow this  
noobsiabot

SDL help - now posted in correct forum :)

This topic is 3343 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(); }

Share this post


Link to post
Share on other sites
Advertisement
Try using the SDL 'get error' function to determine what exactly went wrong (it may just be that you don't have the file in the right location).

Also, use [source][/source] tags when posting code.

Share this post


Link to post
Share on other sites
The most probable reason is that the program can't find the bitmap file.

Remember that Visual Studio's debugger, by default, starts the application in the same path as the project file, not under the debug or release folder. Of course, you can change that in project's settings.

Of course, you can also try to run the executable from outside Visual Studio. Then you should place the executable and the bitmap in the same folder.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!