SDL problem

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Avishaiozeri
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 85
Joined: Wed Mar 17, 2010 4:32 pm

Re: SDL problem

Post by Avishaiozeri »

Live-Dimension wrote:
RyanPridgeon wrote:
Avishaiozeri wrote:
RyanPridgeon wrote:

Code: Select all

#include "SDL.h"

SDL_Surface *screen = NULL;

SDL_Event Event;
int main (int argc, char *argv[])
{
   SDL_Init(SDL_INIT_VIDEO);

   screen = SDL_SetVideoMode(640,480,0,SDL_ANYFORMAT);

   SDL_Surface *img = NULL;
   img = SDL_LoadBMP("a.bmp");
   if (img == NULL) return 1;

   SDL_Surface *ConvertedImg = SDL_DisplayFormat(img);

   while (true)
   {
      if (SDL_PollEvent(&Event) == 0)
      {
      }else{
         if (Event.type == SDL_QUIT)
            break;
      }
   }
   
   return 0;
}
See if that works. If it's returning 1 then it's not loading the BMP succesfully. If it runs then you were doing something wrong in the convert format function, which I haven't looked into and have never used, but SDL_DisplayFormat converts it to the same format as the display, which it looks like you were trying to do yourself, so it would be fine like this.
That's weird, when i run it through the debugger, it runs and then exits, the value returned is 1 (even when the img is in the same directory.) but when running from the actual EXE, it works. does the debugger run the software from a different location and can't find the img?
Yes, haha. I thought this might be the problem. When you run your project from inside your IDE, it's often a different working directory. The working directory is basically what you described. You can probably find it in your IDE options somewhere, or you can just stick your images in the IDE's working directory.

Note that no matter what the IDE does, when you run that exe OUTSIDE the IDE, the working directory will always be where the EXE is located.

Edit: For Codeblocks and Dev - C++, the default working directory for a project is the directory that your project file is located. For example, if your project is called Foo, then you have to put the images in the folder called Foo. I have limited experience for Visual Studio so I cannot recall where it is if you're using that, but I imagine it's similar if not the same.
In visual studio you can change the working directory.
Project properties -> config properties -> debugging -> working directory. set it to $(TargetDir)
Thanks, i'll do that!
Post Reply