SDL 2.0 version of SDL_DisplayFormatAlpha()?
SDL 2.0 version of SDL_DisplayFormatAlpha()?
我开始用 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文档。
相关文章:
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- Mix_Init和Mix_OpenAudio SDL之间的区别是什么
- SDL 窗口不会弹出
- SDL 操纵杆按钮按下/C++
- VSCode IntelliSense无法识别SDL框架的SDL_image扩展库
- C++/SDL "initial value of reference to a non-const must be an lvalue"
- SDL 映像:无法打开映像,仅显示错误消息
- 如何在 3D OpenGL 场景上绘制 SDL 2D 矩形?
- "Undefined symbols for architecture x86_64" 在 SDL 2 (macOS) 中
- 为什么 SDL 在 Mac 上比 Linux 慢得多?
- 在 OSX 上打开 SDL 窗口时不要打开终端窗口
- SDL + OpenGL ES 2.0 使用着色器显示纹理
- SDL GPU 为什么将两个图像分成两个单独的循环更快?
- 在 cmake 中找不到 SDL 库
- SDL/C++: 如何平滑但随机地移动矩形?
- 如何与 SDL 库链接?
- 为什么我的C++代码不呈现 SDL 矩形?
- 为什么要在初始化SDL之前在SDL中声明指针
- C++/SDL 如何覆盖数组?
- 在 SDL 中水平减小静态图像进度条