Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glGetError() returns 1

Tags:

c++

qt

opengl

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.

like image 535
HeavyMight Avatar asked Oct 18 '13 20:10

HeavyMight


2 Answers

Try this instead:

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

Your != was getting evaluated before the =.

like image 84
genpfault Avatar answered Nov 15 '22 04:11

genpfault


I suspect that the following line doesn't do what you want:

GLenum err = glGetError() != GL_NO_ERROR

It first evaluates glGetError() != GL_NO_ERROR, and then assigns it to err.

That's why it's always a good idea to spend 2 more characters in your source code:

(GLenum err = glGetError()) != GL_NO_ERROR

Additional advice: Use glewGetErrorString if you are already using the glew library:

std::cerr << glewGetErrorString(err);
like image 23
leemes Avatar answered Nov 15 '22 04:11

leemes