SDL 2.0 version of SDL_DisplayFormatAlpha()?

SDL 2.0 version of SDL_DisplayFormatAlpha()?

本文关键字:SDL DisplayFormatAlpha of version      更新时间:2023-10-16

我开始用 SDL 2.0 编程。我希望能够将.PNG文件加载到我的程序中,因为.bmp文件没有.png文件那样的所有整洁功能。

我有以下来自 http://www.sdltutorials.com/sdl-image 的代码:

SDL_Surface* loadSurf(char* File) {
SDL_Surface* Surf_Temp = NULL;
SDL_Surface* Surf_Return = NULL;
if((Surf_Temp = IMG_Load(File)) == NULL) {
    return NULL;
}
Surf_Return = SDL_DisplayFormatAlpha(Surf_Temp);
SDL_FreeSurface(Surf_Temp);
return Surf_Return;
}

该函数的重点是加载图像,您将通过执行以下操作来调用它:

SDL_Surface* character = loadSurf("sprite.png");

但是,当我运行它时,在"Surf_Return = SDL_DisplayFormatAlpha(Surf_Temp(;"行。错误是:使用未声明的标识符"SDL_DisplayFormatAlpha">

我认为这是因为代码是为 SDL 1.2 编写的,而我使用的是 SDL 2.0。有没有办法将此功能转换为 SDL 2.0?

我运行的是Mac OSX 10.13.2(如果适用(。

我认为他们从 SDL2 中删除了SDL_DisplayFormatAlpha(和SDL_DisplayFormat(

如果要添加要与从IMG_Load加载表面一起使用SDL_ConvertSurfaceFormat的 Alpha 通道,例如

// Returns a new surface with an alpha channel added
SDL_Surface *new_s = SDL_ConvertSurfaceFormat(surf, SDL_PIXELFORMAT_RGBA8888, 0);

顺便说一下,本教程看起来很旧,您可能需要查看SDL_Image文档。