8

I am using QT 4.8.4 and drawing OpenGL on QGraphicsScene background. The problem is that I am getting invalid return from glGetError(). My code snippet:

while (GLenum err = glGetError() != GL_NO_ERROR) {
    std::cerr << err;        
}

On application output I get a lot of lines with number 1

From the documentation I see possible values are:

GL_NO_ERROR, GL_INVALID_ENUM, GL_INVALID_VALUE, GL_INVALID_OPERATION, GL_INVALID_FRAMEBUFFER_OPERATION, GL_OUT_OF_MEMORY, GL_STACK_UNDERFLOW, GL_STACK_OVERFLOW

which are defined as 0, 0x0500, 0x0501, 0x0502, 0x0503, 0x0504, 0x0505, 0x0506.

How is it possible I get the 1 instead of a proper error code?

This started to happen when I wrapped my native OpenGL drawing code with QT's:

painter->beginNativePainting();
...
painter->endNativePainting();

PS: The multiple 1's are from multiple draw calls and not from the loop.

4

2 回答 2

6

试试这个:

GLenum err;
while ( ( err = glGetError() ) != GL_NO_ERROR) {
    std::cerr << err;        
}

!==.

于 2013-10-18T21:05:00.937 回答
3

我怀疑以下行不符合您的要求:

GLenum err = glGetError() != GL_NO_ERROR

首先评估glGetError() != GL_NO_ERROR然后将其分配给err

这就是为什么在源代码中多花 2 个字符总是一个好主意:

(GLenum err = glGetError()) != GL_NO_ERROR

附加建议:glewGetErrorString如果您已经在使用该glew库,请使用:

std::cerr << glewGetErrorString(err);
于 2013-10-18T21:05:16.067 回答