PDA

View Full Version : Playing sound in OpenGL



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

exile79
08-23-2009, 10: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

scratt
08-23-2009, 10:58 AM
OpenAL. :)

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

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

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

Ilian Dinev
08-23-2009, 12:04 PM
exile79 already showed you how.

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

Ilian Dinev
08-23-2009, 12:36 PM
http://msdn.microsoft.com/en-us/library/ms713269%28VS.85%29.aspx

madman420
08-23-2009, 11: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.