C ++ SDL2 |如何在SDL2中播放GIF?

时间:2016-03-28 17:49:18

标签: c++ sdl-2

我知道这个话题已经提出来了,但我从来没有从页面中得到任何东西。我的答案的一个线索是我需要将GIF分成每个帧,但是如何?一些代码以及这将非常感谢。 非常感谢。

1 个答案:

答案 0 :(得分:2)

Use GIFLIB to read gif animations. GIFLIB provides a handy "slurp" function that reads the entire file into structs that you can then pretty easily retrieve your frames from. It's been a while but IIRC when building an SDL_Texture from the one gif frame you will need to look up colors from a palette for each pixel. Since gifs don't have one fixed frame rate you will also need to store the individual delay times for each frame. Read this for a detailed description of the gif file format and it will help you make sense of GIFLIB.

That said, I would advise against using the clunky GIF format for cutscenes (and most other things) because it's pretty space hungry and you may have problems syncing up your audio nicely. I would recommend looking around for a way to play "real" video formats -- take a look at this project.