介绍了openal的基本用法
ALCfloatsourceTwoPos[] = {-2,0,-2}; ALCfloatsourceTwoVel[] = {1,1,1}; alSourcefv(sourceTwoIndex,AL_POSITION,sourceTwoPos); alSourcefv(sourceTwoIndex,AL_VELOCITY,sourceTwoVel); alSourcei(sourceTwoIndex,AL_LOOPING,AL_TRUE); alSourcef(sourceTwoIndex,AL_GAIN,1); alSourcef(sourceTwoIndex,AL_PITCH,1); // 设置听者的信息 ALCfloatlistenerPos[] = {0,0,-1}; ALCfloatlistenerVel[] = {0,0,0}; ALCfloatlistenerOri[] = {0,0,-1,0,1,0}; alListenerfv(AL_POSITION,listenerPos); alListenerfv(AL_VELOCITY,listenerVel); alListenerfv(AL_ORIENTATION,listenerOri); charchoose = '0'; alSourcePlay(sourceIndex); alSourcePlay(sourceTwoIndex); while (choose != 'q') { choose = getchar(); switch(choose) { case'w': sourcePos[0] -= sourceVel[0]; sourcePos[1] -= sourceVel[1]; sourcePos[2] -= sourceVel[2]; alSourcefv(sourceIndex,AL_POSITION,sourcePos); if (alGetError() != AL_NO_ERROR) { } alSourcei(sourceIndex, AL_SOURCE_RELATIVE, AL_FALSE); break; sourcePos[0] += sourceVel[0]; sourcePos[1] += sourceVel[1]; sourcePos[2] += sourceVel[2]; alSourcefv(sourceIndex,AL_POSITION,sourcePos); if (alGetError() != AL_NO_ERROR) { // 出错 exit(0); case's':