c++ - SDL-Image:无法打开图像,只有错误消息
问题描述
Game Engine Creation 课程作业,关于 SDL 的问题,目前正在学习 C++ SDL。遇到一个关于 SDL_Image 的问题,无法打开图像。
当我运行代码时它立即关闭
bool InitSDL()
{
//Setup SDL
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
cout << "SDL did not initialise. Error: " << SDL_GetError();
return false;
}
else
{
gWindow = SDL_CreateWindow(
"GEC_SDL",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH,
SCREEN_HEIGHT,
SDL_WINDOW_SHOWN
);
if (gWindow == NULL)
{
cout << "Window was not created. Error: " << SDL_GetError();
return false;
}
}
gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED);
if (gRenderer != NULL)
{
cout << "Renderer initialised." << endl;
//Initialise PNG loading.
int imageFlags = IMG_INIT_PNG;
if (!(IMG_Init(imageFlags) & imageFlags))
{
cout << "SDL_Image could not initialise. Error: " << IMG_GetError;
return false;
}
else {
cout << "SDL_Image initialised." << endl;
}
}
else
{
cout << "Renderer could not initialise. Error: " << SDL_GetError;
return false;
}
gTexture = LoadTextureFromFile("D:/_a'Programs/School/GEC_SDL/GEC_SDL/Images/text.bmp");
if (gTexture == NULL)
{
return false;
}
return true;
}
尝试完整路径:D:_a'Programs\School\GEC_SDL\GEC_SDL\Images
从文件函数加载纹理
SDL_Texture* LoadTextureFromFile(string path)
{
FreeTexture();
SDL_Texture* pTexture = NULL;
//Load the image.
SDL_Surface* pSurface = IMG_Load( path.c_str() );
if (pSurface != NULL)
{
//Create the texture from the pixels on the surface.
pTexture = SDL_CreateTextureFromSurface(gRenderer, pSurface);
if (pTexture == NULL)
{
cout << "Unable to create texture from surface. Error: " << SDL_GetError() << endl;
}
SDL_FreeSurface(pSurface);
}
else
{
cout << "Unable to create texture from surface. Error: " << IMG_GetError() << endl;
}
return pTexture;
}
我在论坛中搜索了类似的问题并尝试了他们的方法,它们都不起作用,请帮助。
解决方案
OMG,是的,这是'
问题,我重命名了文件夹,现在它可以工作了......
PS:愚蠢的字符集
推荐阅读
- youtube-api - 如何使用 YouTube Data API v3 启动默认的“Go Live”流
- blockchain - web3.contract.functions.getAmount() 中的差异
- list - Prolog 列表递归的问题不断返回预期的语法错误运算符
- ruby - 为什么 end_game 有 NoMethodError?
- uno-platform - 不起作用的 ListView GetContainerForItemOverride 方法
- python - 修复 Tensorflow Conv-Neural-Network 上的 ValueError 和 Warning
- python - ValueError: rate 必须是标量张量或范围 [0, 1) 内的浮点数,得到 1
- c++ - 如何将具有不同参数的函数放入 C++ 中的映射中?
- c - val = &(a->bc) 不等于 x=a->b; val = &(xc) 在 C 中?
- c# - 以管理员身份运行进程后台任务