当我尝试加载 png 文件时,返回错误“不支持的图像格式”。人们之前已经在 StackOverflow 上发布了关于这个主题的帖子,但似乎没有一个解决方案对我有用。
我在 Linux 机器上工作,用 g++ 编译
这是我的图书馆...
#include <SDL2/SDL.h>
#include <SDL/SDL_image.h>
#include <stdio.h>
#include <string>
#include <zlib.h>
#include <png.h>
Run Code Online (Sandbox Code Playgroud)
当我编译时,我包含了 -lSDL2 和 -lSDL_image 标志。我不使用 SDL2/SDL_image.h,因为它没有安装在我正在使用的机器上。此外,我的 png 文件肯定与我尝试加载它的代码位于同一目录中,我确实调用了 IMG_Init(IMG_INIT_PNG) 和 IMG_INIT_PNG。
这是我的代码,错误发生在 loadSurface 函数中(我相信)。
//Using SDL, SDL_image, standard IO, and strings
#include <SDL2/SDL.h>
//#include <SDL/SDL_version.h>
#include <SDL/SDL_image.h>
#include <stdio.h>
#include <string>
#include <zlib.h>
#include <png.h>
//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
//Starts up SDL and creates window
bool init();
//Loads …Run Code Online (Sandbox Code Playgroud)