问题
I've just started with SDL after doing some research. I started with this tutorial http://lazyfoo.net/SDL_tutorials/lesson01/index2.php << Using the exact same code and bmp image.
For some reason when I debug and run the program inside my IDE (Microsoft visual studio) the screen loads but the picture that should be popping up on the screen does not. However, when I would go to my project and run the program manually it does everything smoothly. After doing some research it turned out SDL_LoadBMP() returns NULL (it returns NULL if an error occured). But why? Also, how can I see what the error actually is?
回答1:
Is the bitmap you're trying to load in the correct directory? When you launch your program from Visual Studio, it starts with the current working directory in the directory where your project (.vcproj
or .vcxproj
file) is contained. Make sure your paths are all relative to that directory.
However, if you're launching by double-clicking the executable in Windows Explorer (which is typically in a Debug\
or Release\
subdirectory by default), then it starts with a current working directory of that folder.
回答2:
Several problems could occur:
- Do you have SDL_image installed?
- Are you linking to SDL_image?
- Do you have the actual graphics file in the proper folder?
- Are you blitting the screen?
- Are you using SDL_Flip?
来源:https://stackoverflow.com/questions/11979632/c-sdl-why-does-sdl-loadbmp-return-null