且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 OSX 下的 SDL/OpenGL 应用程序中加载 JPG/PNG 纹理

更新时间:2023-10-20 11:10:46

看看SDL_image 图书馆.它提供了诸如 IMG_LoadPNG 之类的功能,可以将您的图片作为"SDL_Surface 加载.由于您已经使用 SDL,因此这应该非常适合您的程序.

Have a look at the SDL_image library. It offers functions like IMG_LoadPNG that load your picture "as an" SDL_Surface. Since you already work with SDL this should fit quite well in your program.

取自 SDL_image 文档的示例:

// Load sample.png into image
SDL_Surface* image = IMG_Load("sample.png");
if (image == nullptr) {
    std::cout << "IMG_Load: " << IMG_GetError() << "
";
}