From 5078b44ec842da4bb4b749fa9c969a65daecfb51 Mon Sep 17 00:00:00 2001 From: Vladimir Gamalian Date: Fri, 14 Aug 2015 11:27:47 +0700 Subject: [PATCH] Add sdl mixer lib init/deinit --- SDL2pp/SDLMixer.cc | 13 +++++++------ SDL2pp/SDLMixer.hh | 15 +++------------ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/SDL2pp/SDLMixer.cc b/SDL2pp/SDLMixer.cc index b9c0b0f..7d106d3 100644 --- a/SDL2pp/SDLMixer.cc +++ b/SDL2pp/SDLMixer.cc @@ -27,23 +27,24 @@ namespace SDL2pp { SDLMixer::SDLMixer(int flags) { - if ((IMG_Init(flags) & flags) != flags) - throw Exception("IMG_Init"); + if ((Mix_Init(flags) & flags) != flags) + throw Exception("Mix_Init"); } SDLMixer::~SDLMixer() { - IMG_Quit(); + while(Mix_Init(0)) + Mix_Quit(); } int SDLMixer::InitMore(int flags) { int ret; - if (((ret = IMG_Init(flags)) & flags) != flags) - throw Exception("IMG_Init"); + if (((ret = Mix_Init(flags)) & flags) != flags) + throw Exception("Mix_Init"); return ret; } int SDLMixer::GetInitFlags() { - return IMG_Init(0); + return Mix_Init(0); } } diff --git a/SDL2pp/SDLMixer.hh b/SDL2pp/SDLMixer.hh index 91fd2b0..bd2225d 100644 --- a/SDL2pp/SDLMixer.hh +++ b/SDL2pp/SDLMixer.hh @@ -31,20 +31,11 @@ namespace SDL2pp { /// /// \headerfile SDL2pp/SDLMixer.hh /// -/// Though it's possible to use SDL_mixer without initializing it, -/// library provides initialization/deinitialization functions to -/// be able to preload libraries for specific file format support -/// (png, jpeg or tiff) beforehand. In SDL2pp, this is handled by -/// this class. -/// /// Usage example: /// \code /// int main() { /// SDL2pp::SDL sdl(SDL_INIT_VIDEO); -/// SDL2pp::SDLMixer mixer(IMG_INIT_PNG); -/// -/// // use SDL_mixer functions -/// SDL2pp::Texture t("/path/to/file.png"); +/// SDL2pp::SDLMixer mixer(MIX_INIT_OGG); /// /// // SDL_mixer library is automatically deinitialized before exit /// return 0; @@ -57,7 +48,7 @@ public: //////////////////////////////////////////////////////////// /// \brief Initializes SDL_mixer library /// - /// \param[in] flags Flags to pass to IMG_Init() + /// \param[in] flags Flags to pass to Mix_Init() /// /// \throws SDL2pp::Exception /// @@ -77,7 +68,7 @@ public: //////////////////////////////////////////////////////////// /// \brief Try to init more SDL_mixer formats /// - /// \param[in] flags Flags to pass to IMG_Init() + /// \param[in] flags Flags to pass to Mix_Init() /// /// \throws SDL2pp::Exception ///