【发布时间】:2015-02-04 20:07:28
【问题描述】:
我正在学习一个教程,我认为我做的一切都是正确的,但它继续说“不支持的图像格式”。
代码:
SDL_Texture *LoadTexture(string filePath, SDL_Renderer *renderTarget)
{
SDL_Texture *texture = nullptr;
SDL_Surface *surface = IMG_Load(filePath.c_str());
if (surface == NULL)
{
cout << "Error: " << IMG_GetError() << endl;
}
else
{
texture = SDL_CreateTextureFromSurface(renderTarget, surface);
if (texture == NULL)
{
cout << "Error: " << SDL_GetError() << endl;
}
}
SDL_FreeSurface(surface);
return texture;
}
表面在接受IMG_Load()的结果后保持NULL;
另外,我的包括:
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL/SDL_image.h>
还有,我的初始化:
SDL_Init(SDL_INIT_VIDEO);
int image_flags = IMG_INIT_PNG;
if (IMG_Init(image_flags) != image_flags)
{
cout << "Error: " << IMG_GetError() << endl;
}
另外,以防万一,我在 Ubuntu 中执行此操作,并且我最近从 Windows 切换,所以我可能无法正确处理库。
编辑:如果您要问,我正在尝试使用 PNG,所以我没有使用我尚未初始化的格式
【问题讨论】:
标签: linux image ubuntu sdl sdl-2