Initializing FMOD

The first code that we need to add is the code that will initialize the audio engine. Just like we must initialize OpenGL, the code will set up FMOD and check to see if there are any errors along the way.

Open RoboRacer2D.cpp and add the following code to the variable declarations area:

FMOD::System* audiomgr;

Then add the following function:

bool InitFmod()
{
  FMOD_RESULT result;
  result = FMOD::System_Create(&audiomgr);
  if (result != FMOD_OK)
  {
    return false;
  }
  result = audiomgr->init(50, FMOD_INIT_NORMAL, NULL);
  if (result != FMOD_OK)
  {
    return false;
  }
  return true;
}

This function creates the FMOD system and initializes it:

  • First, we define a variable to catch FMOD error codes
  • The System_Create call creates the engine and stores the ...

Get OpenGL Game Development By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.