1 / 16

3D Game Programming OpenAL

3D Game Programming OpenAL. Ming-Te Chi Department of Computer Science,  National Chengchi University. Goal. OpenAL programming. OpenAL #include <alal.h> #include <alalu.h> #include <alalc.h> ALUT #include <alalut.h>. Package download. Linker – wxdev C++. Init. In main()

Télécharger la présentation

3D Game Programming OpenAL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 3D Game ProgrammingOpenAL Ming-Te Chi Department of Computer Science,  National Chengchi University

  2. Goal • OpenAL programming

  3. OpenAL • #include <al\al.h> • #include <al\alu.h> • #include <al\alc.h> • ALUT • #include <al\alut.h>

  4. Package download

  5. Linker – wxdev C++

  6. Init In main() //initialise openAL alutInit(&argc, argv) ;

  7. Fundamental OpenAL objects OpenAL Programmer's Guide

  8. Listener • For every context, there is automatically one Listener object. alListenerfv(AL_POSITION, listenerPos); alListenerfv(AL_VELOCITY, listenerVel); alListenerfv(AL_ORIENTATION, listenerOri);

  9. Buffer • Each buffer generated by alGenBuffers has properties which can be retrieved.

  10. const int NUM_BUFFERS = 3; ALuint buffer[NUM_BUFFERS]; ALboolean al_bool; ALsizei size,freq; ALenum format; ALvoid *data = NULL; int ch; // Generate buffers, or no sound will be produced alGenBuffers(NUM_BUFFERS, buffer); if(alGetError() != AL_NO_ERROR) { printf("- Error creating buffers !!\n"); exit(1); } else { // printf("Created buffers\n"); } alutLoadWAVFile("c.wav", &format ,&data, &size, &freq, &al_bool); alBufferData(buffer[0], format, data, size, freq); alutUnloadWAV(format, data, size, freq);

  11. Source • A source in OpenAL is exactly what it sounds like, a source of a sound in the world.

  12. const int NUM_SOURCES = 3; ALuint source[NUM_SOURCES]; alGetError(); /* clear error */ alGenSources(NUM_SOURCES, source); if(alGetError() != AL_NO_ERROR) { printf("- Error creating sources !!\n"); exit(2); } alSourcef(source[0], AL_PITCH, 1.0f); alSourcef(source[0], AL_GAIN, 1.0f); alSourcefv(source[0], AL_POSITION, source0Pos); alSourcefv(source[0], AL_VELOCITY, source0Vel); alSourcei(source[0], AL_BUFFER, buffer[0]); //attach buffer alSourcei(source[0], AL_LOOPING, AL_TRUE);

  13. Play and Stop Combine with keyboardfunc(), or some other way Ex: • alSourcePlay(source[0]); • alSourceStop(source[0]); • alSourcePause(source[0]);

  14. Exit • In main() // Setup an exit procedure. atexit(KillALData); • void KillALData() • { • alDeleteSources(NUM_SOURCES, source); alDeleteBuffers(NUM_BUFFERS, buffers); • alutExit(); • }

  15. Reference • devmaster • http://www.devmaster.net/articles.php?catID=6 • A Guide To Starting With OpenAL • http://www.gamedev.net/reference/articles/article2008.asp

More Related