简体   繁体   中英

C++ SDL2 | How do I play a GIF in SDL2?

I am aware that this topic has already been brought up, but I never could get anything out of the page. One clue to my answer was that I need to split up the GIF into each of its frames, but how? Some code along with this would be greatly appreciated. Thanks a lot.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM