View Full Version : Playing sound in OpenGL

Creative Mind
08-23-2009, 08:28 AM
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??

08-23-2009, 09:36 AM
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

08-23-2009, 09:58 AM
OpenAL. :)

Creative Mind
08-23-2009, 10:54 AM
what is wav.h ?!!

isn't it a standard header??? i think it's a c++ header...

Creative Mind
08-23-2009, 11:01 AM
how do we play sounds in c++ ??

Ilian Dinev
08-23-2009, 11:04 AM
exile79 already showed you how.

Creative Mind
08-23-2009, 11:21 AM
it's asking for <userint.h> ???

Ilian Dinev
08-23-2009, 11:36 AM

08-23-2009, 10:35 PM
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 (http://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 (http://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.