GlGetError () returns 1

I use QT 4.8.4 and draw OpenGL against the background of QGraphicsScene. The problem is that I get an invalid return from glGetError () . My code snippet:

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

In the output of the application, I get a lot of lines with number 1

From the documentation, I see the possible values:

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 this possible I get 1 instead of the correct error code?

It started when I wrapped my own OpenGL drawing code with QT:

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

PS: Set 1 of several drawing calls, not a loop.

+6
source share
2 answers

Try this instead:

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

Your != Was rated to = .

+5
source

I suspect the following line does not do what you want:

 GLenum err = glGetError() != GL_NO_ERROR 

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

This is why it is always useful to spend 2 more characters in the source code:

 (GLenum err = glGetError()) != GL_NO_ERROR 

Additional tips: use glewGetErrorString if you are already using the glew library:

 std::cerr << glewGetErrorString(err); 
+2
source

Source: https://habr.com/ru/post/956287/


All Articles