Any game would be incomplete if it did not have any background music. So it is very important that we integrate a way to play music into our C++ engine. There are various ways to do this. We are going to use SDL to play music in our game.
You need a Windows machine and a working copy of Visual Studio. The SDL library is also required.
In this recipe, we will find out how easy it is to play background music:
Add a source file called
Source.cpp
.#include <iostream> #include "../AudioDataHandler.h" #include "../lib/SDL2/include/SDL2/SDL.h" #include "iaudiodevice.hpp" #include "iaudiocontext.hpp" #include "audioobject.hpp" #include "sdl/sdlaudiodevice.hpp" #include "sdl/sdlaudiocontext.hpp" #define FILE_PATH "./res/audio/testClip.wav" int main(int argc, char** argv) { SDL_Init(SDL_INIT_AUDIO); IAudioDevice* device = new SDLAudioDevice(); IAudioContext* context = new SDLAudioContext(); IAudioData*...