我正在使用笔式驱动器运行 ubuntu 12.04。我已经安装了 openAL 并且我的主要是:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <al.h>
#include <alc.h>
// Buffers hold sound data.
ALuint Buffer;
using namespace std;
string ErrorCheck(ALenum error)
{
if(error == AL_INVALID_NAME)
{
return "Invalid name";
}
else if(error == AL_INVALID_ENUM)
{
return " Invalid enum ";
}
else if(error == AL_INVALID_VALUE)
{
return " Invalid value ";
}
else if(error == AL_INVALID_OPERATION)
{
return " Invalid operation ";
}
else if(error == AL_OUT_OF_MEMORY)
{
return " Out of memory like! ";
}
return " Don't know ";
}
int main(int argc, char **argv)
{
ALenum error;
error = alGetError();
cout << "\n\tInitial error at start of program - " << ErrorCheck(error);
error = alGetError();
cout << "\n\tError persists - " << ErrorCheck(error);
cout << "\n\tGenerating buffer...";
alGenBuffers(1, &Buffer);
error = alGetError();
if(error != AL_NO_ERROR)
{
cout << "\n\tError generating buffer - "<< ErrorCheck(error) << "\n\n";
return 0;
}
return 0;
}
这使用该行编译没有错误
g++ main.cpp -I/usr/include/AL -lopenal -lalut
但是当程序运行时,对 alGetError() 的每次调用都会返回 AL_INVALID_OPERATION 我认为调用 alGetError() 是为了重置错误标志,所以我在开始时调用它两次,第二次调用至少应该不返回错误。我真的被困住了!