SDL_Image IMG_Load()表示不支持文件格式

时间:2015-02-04 20:07:28

标签: linux image ubuntu sdl sdl-2

我正在关注一个教程,我认为我已经做好了一切,但它继续说"不支持的图像格式"。

代码:

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,所以我没有使用我尚未初始化的格式

1 个答案:

答案 0 :(得分:2)

改变这个:

#include <SDL/SDL_image.h> 

#include <SDL2/SDL_image.h>

您目前正在使用带SDL2的SDL_image(来自SDL1)标头,我认为您的问题就在那里。如果没有安装,可能需要安装SDL2_image-dev。

相关问题