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

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

最佳答案

改变这个:

#include <SDL/SDL_image.h> 

#include <SDL2/SDL_image.h>

您当前正在将 SDL_image(来自 SDL1) header 与 SDL2 一起使用,我认为您的问题就在那里。如果未安装,您可能需要安装 SDL2_image-dev。

关于linux - SDL_Image IMG_Load() 表示不支持文件格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28330486/

相关文章:

c - 如何使用 C 在文件中查找字符串并在该搜索字符串的下一行写入新字符串

java - Java运行时执行shell脚本时会在哪里创建nohup.out文件?

linux - 在 Linux 11.04 上安装 TBB

android - 如何在 Android 中显示来自 GridView Activity 的图像预览

android - 处理不同尺寸照片的移动应用程序和服务器的设计

php - Yii2 basepath URL 在 linux 和 windows 中不同吗?

linux - 在 nodejs 的部署服务器上初始化 git

linux - 如何使用 shell 脚本选择一行?

html - 我如何强制缩小的 svg 图像彼此相邻排列而不是换行/被推到下一行?

amazon-web-services - Aws Ec2 初始启动时设备上没有剩余空间,我丢失了 pem key 文件,因此无法 ssh