Sounds( OpenAL ) in OpenGL

Hi People

I started to learn openGL and OpenAL. I would appreciate your help.

I am coding OpenGL and OpenAL in console environment (visual c++). Just wondered how to combine those OpenGL and OpenAL mains functions. I mean the only way is that for example use alutInit() and glutInit() together or I can modularize them?

Another question, My little simple program shows a cube rotating. I added a few lines and using glutKeyboardFunc(keyfunc) called below function:

void keyfunc (unsigned char key, int x , int y)
   case 's':

and The play() function:

void play()
  ALuint helloBuffer, helloSource;
  helloBuffer = alutCreateBufferHelloWorld ();
  alGenSources (1, &helloSource);
  alSourcei (helloSource, AL_BUFFER, helloBuffer);
  alSourcePlay (helloSource);
  alutSleep (1);
  alutExit ();  

It sounds weird to me. when I push ‘s’ the whole screen stops, the function plays the sound and again animation starts. I want the animation remain in action while the sound is playing. what should I do?

P.S: I used alutInit() in main function.

You should be able to use OpenAL and OpenGL together. OpenAL was designed for people that were somewhat familiar with OpenGL.

The alutSleep function pauses exection of the entire thread for a certain amount of time ( in your case, 1 second). So, when you hit ‘s’, the play function executes, gets to the sleep call, and stops for 1 second, then continues. Is your sound 1 second long? That would explain why the animation starts up when the sound stops.

I’m not that familiar with OpenAL, but it seems like you should not be creating sources and buffers and destroying them to play the sound. In fact, if you want to use ALUT more, you shouldn’t exit from it after playing the sound, unless you call alutInit again.

Remove these :
alutSleep (1); // why to you want to sleep anyway ? it will block the rendering
alutExit ();

And your AL buffers handling leaves to be desired, but that is problably the least of your worries :slight_smile:

Funny Mistakes :smiley:
Thanx fellas …