C++ SDL, why does SDL_LoadBMP() return NULL?

拈花ヽ惹草 提交于 2019-12-13 06:06:09

问题


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:

  1. Do you have SDL_image installed?
  2. Are you linking to SDL_image?
  3. Do you have the actual graphics file in the proper folder?
  4. Are you blitting the screen?
  5. Are you using SDL_Flip?


来源:https://stackoverflow.com/questions/11979632/c-sdl-why-does-sdl-loadbmp-return-null

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!