Playing sound in OpenGL

I want to play .wav sounds in my program. I’m directed to use a wav.h file but what i got is may be corrupted or incomplete…
So, i’ve 2 Qs:

  1. How can I play simple .wav sounds as background and foreground music.

  2. Is there any standard wav.h file??

as far as i can tell, playing sounds has nothing to do with OpenGL as it is a purely 3D API, meaning that all it can do is handle graphics.
Now, there can be many ways to play a simple sound depending of the system you are developing in.
For example, in windows, you could check this http://zone.ni.com/devzone/cda/epd/p/id/1067

OpenAL. :slight_smile:

what is wav.h ?!!

isn’t it a standard header??? i think it’s a c++ header…

how do we play sounds in c++ ??

exile79 already showed you how.

it’s asking for <userint.h> ???

Good question. OpenGL is short for “Open Graphics Library”. It provides many (C programming) functions for the display and manipulation of 2D and 3D graphics. For anything else, you will need to call another function in a different library.

If you are programming for MS Windows and you follow the link Ilian Dinev posted, you will be taken to the sndPlaySound function of the Windows API <windows.h>, which is simple to use, but will not work for other platforms such as MAC OS X and GNU/Linux.

If you might want to port your app to run on many platforms (you’re an o.g.), you should use something like PortAudio <www.portaudio.com>. It’s a portable (runs on windows,mac,linux,etc) audio library, and is supposed to be easy to use as well.

OpenAL <www.openal.org> is the probably the best companion to OpenGL. It is, like OpenGL, cross-platform and even has functions for 3D sound! I haven’t used it myself, yet, but it appears to (finally) be mature enough for production use.