Development/Tutorials/Games/KALEngine: Difference between revisions

From KDE TechBase
No edit summary
No edit summary
Line 36: Line 36:


== Hello Word ==
== Hello Word ==
<code cppqt>
#include <KALEngine>
#include <KALSource>
#include <KDebug>
int main(int argc, char **argv)
{
    KALEngine snd; //create an openAL object
    snd.init(); // Initialize OpenAL Context + Device!
    KALSource *son = new KALSource(); // create a sample, if no argument, It will play an "hello world"
    son->play(); // play the sound!!
    while (son->getStatus() == AL_PLAYING) // wait while sound is playing
    {
      kDebug()<<son->getElapsedTime(); //print the elapsed time.
    }
    delete son; //when it finished! Don't forget to clear the buffer!!
    snd.shutdown(); // and close the device!!
    return 0;
}
</code cppqt>

Revision as of 11:56, 13 February 2009

KALEngine tutorial
Tutorial Series   KALEngine developement
Prerequisites   None
What's Next   Nothing at the moment
Further Reading   KGLEngine2d's code

Abstract

Phonon is not really designed to handle multiple sounds at the same time. KALEngine is made for games and create one thread per sound, using the excellent openAL librairy. you also get all the other openAL goodness like 3D sounds, effects and multichannel.

Installation

1: Be sure you have installed dependent librairy. - openAL ( sound api) - alut (openal toolkit) - libSndFile (load sound file).

2: compile and install kalengine from svn : /trunk/playground/games/KALEngine/

Hello Word

  1. include <KALEngine>
  2. include <KALSource>
  3. include <KDebug>

int main(int argc, char **argv) {

   KALEngine snd; //create an openAL object
   snd.init(); // Initialize OpenAL Context + Device!
   KALSource *son = new KALSource(); // create a sample, if no argument, It will play an "hello world"
   son->play(); // play the sound!!


   while (son->getStatus() == AL_PLAYING) // wait while sound is playing
   {
     kDebug()<<son->getElapsedTime(); //print the elapsed time.
   }


   delete son; //when it finished! Don't forget to clear the buffer!!
   snd.shutdown(); // and close the device!!


   return 0;

}