IMG_Load故障(不支持图像格式)

IMG_Load troubles (unsupported image format)

本文关键字:图像 格式 不支持 Load 故障 IMG      更新时间:2023-10-16

操作系统Ubuntu;IDE代码块我编写了自己的纹理管理器类,带有"加载"功能

    bool TextureManager::load(std::string fileName, std::string id, SDL_Renderer* pRenderer)
    {
    SDL_Surface* pTempSurface = IMG_Load(fileName.c_str());
    if(pTempSurface == NULL) {
    printf("IMAGE LOAD ERROR: %s n", IMG_GetError());
    return false;
    }
    SDL_Texture* pTexture = SDL_CreateTextureFromSurface(pRenderer, pTempSurface);
    SDL_FreeSurface(pTempSurface);
    // everything went ok, add the texture to our list
    if(pTexture != 0) {
        m_textureMap[id] = pTexture;
        return true;
    }
    // reaching here means something went wrong
    return false;
    }

它写着"图像加载错误:不支持的图像格式"

但我包含了SDL_image所需的所有内容:

  #include <png.h>
  #include <zlib.h>  

没有这个texturereloader,IMG_load()正常工作。那是什么?我该怎么修?

您不需要包括这些标头,只需要SDL_image

你初始化它了吗?例如

/*! initialize PNG support */
IMG_Init(IMG_INIT_PNG);