Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
OpenGL Game Development By Example

You're reading from   OpenGL Game Development By Example Design and code your own 2D and 3D games efficiently using OpenGL and C++

Arrow left icon
Product type Paperback
Published in Mar 2016
Publisher
ISBN-13 9781783288199
Length 340 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Robert Madsen Robert Madsen
Author Profile Icon Robert Madsen
Robert Madsen
Stephen Madsen Stephen Madsen
Author Profile Icon Stephen Madsen
Stephen Madsen
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

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 results in audiomgr

  • We then initialize FMOD with 50 virtual channels, normal mode, and

Finally, we need call the InitAudio function. Modify the GameLoop function, adding the highlighted line:

void GameLoop(const float...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image