【发布时间】:2014-09-01 19:27:47
【问题描述】:
每次调用 OpenGL 函数后,我都会在代码中添加 glGetError()。
实际上我没有调用glGetError(),而是我编写的一个函数(DisplayGlErrors())在控制台中打印所有错误(通过循环)。所以现在我想,每次我在(例如)gluLookAt() 之后立即调用我的函数时,我应该能够通过该函数获取由 openGL 引起的所有错误。
现在谈谈我的问题。从这段代码:
GL_engine::GL_engine(Application* appli):engine(appli), width(get_parent()->getWidth()), height(get_parent()->getHeight())
{
if (GLEW_OK != glewInit()) // glew needs to be initialised, otherwise we get an error, AFTER a windows has been created BUT BEFORE using buffers
{
std::cout << "glewInit() failed" << std::endl;
exit(EXIT_FAILURE);
}
DisplayGlErrors(__FILE__, __LINE__);
glGetIntegerv( GL_MAJOR_VERSION, &contextMajor ); DisplayGlErrors(__FILE__, __LINE__);
glGetIntegerv( GL_MINOR_VERSION, &contextMinor ); DisplayGlErrors(__FILE__, __LINE__);
std::cout << "Created OpenGL " << contextMajor <<"."<< contextMinor << " context" << std::endl;
glClearColor(0.25f, 0.25f, 0.25f, 1.0f); DisplayGlErrors(__FILE__, __LINE__);
cam = Camera(); DisplayGlErrors(__FILE__, __LINE__);
worldAxis.initialise(); DisplayGlErrors(__FILE__, __LINE__); DisplayGlErrors(__FILE__, __LINE__);
worldGrid.initialise(); DisplayGlErrors(__FILE__, __LINE__); DisplayGlErrors(__FILE__, __LINE__);
}
我得到了(在控制台中):
OpenGL error #1: INVALID_ENUM(/WelcomeToYourPersonalComputerInferno/666/src/GL_engine.cc, 40)
OpenGL error #1: INVALID_ENUM(/WelcomeToYourPersonalComputerInferno/666/src/GL_engine.cc, 41)
Created OpenGL 0.0 context
n.b. : contextMajor 和 contextMinor 是 GLint 变量。
我不知道这些 INVALID_ENUM 是什么意思...我什至认为 OpenGL 也不知道...
if for any reason you want to look inside my code, I just updated my git
最后,因为我在我的程序中使用 GLFW、GLU、GLEW。我想知道在我从这些库中调用一个函数之后调用glGetError()(仍然是DisplayGlErrors())是否有意义。
【问题讨论】: