Context & stateGL 1.0

glGetError

Returns (and clears) the oldest error flag recorded by previous calls.

Part of the family glGet*

Signature

GLenum glGetError(void);

How it works

OpenGL functions do not return error codes. When a call is invalid it is ignored and an error flag is set. glGetError reads that flag and resets it, so you must call it in a loop until it returns GL_NO_ERROR to empty all pending errors.

It tells you THAT something failed, not WHERE. On OpenGL 4.3+ the debug callback (glDebugMessageCallback) is far more useful.

Return value

GL_NO_ERROR, or one of: GL_INVALID_ENUM, GL_INVALID_VALUE, GL_INVALID_OPERATION, GL_INVALID_FRAMEBUFFER_OPERATION, GL_OUT_OF_MEMORY, GL_STACK_OVERFLOW, GL_STACK_UNDERFLOW.

Tips & pitfalls

  • Each call can stall the pipeline. Wrap it in a debug-only macro instead of shipping it.

Example

example.cpp
1#define GL_CHECK(x) do { x; \
2    for (GLenum e; (e = glGetError()) != GL_NO_ERROR;) \
3        std::fprintf(stderr, "GL error 0x%X at %s:%d\n", e, __FILE__, __LINE__); \
4} while (0)
5
6GL_CHECK(glBindTexture(GL_TEXTURE_2D, tex));
Official Khronos documentation