Notes

Thoughts, write-ups, and things worth remembering.

OpenGL debugging

#graphics#opengl#debugging Updated Oct 13, 2026

Most OpenGL mistakes fail silently: no crash, just a black or empty window. Errors have to be requested explicitly.

How GL reports errors

  • gl calls return nothing on failure. They set an internal error flag and keep going.
  • glGetError() reads the flag and clears it. The flag sticks until read, so one check at the end can’t tell which call failed.
  • To locate a failure: check after every suspect call; the first check that fires sits right after the culprit. Put a breakpoint in the error branch and read the call stack.
glBindBuffer(...);              printGLErrorLog();
glEnableVertexAttribArray(-1);  printGLErrorLog();  // stops here

hw04’s printGLErrorLog() ends with a bare throw;, which terminates the program. Run under the debugger to stop there instead of exiting.

Remove per-frame checks once things work; they cost performance.

ErrorUsual cause
GL_INVALID_VALUEBad number, e.g. location -1
GL_INVALID_OPERATIONNot allowed in current state: uniform without glUseProgram, uniform type mismatch
GL_INVALID_ENUMWrong constant for that parameter

Symptom → cause

SymptomCheck
Nothing drawnAttribute enabled? bind before pointer? index count right? glUseProgram?
Shape is a dot or missingglVertexAttribPointer component count, buffer byte size
Only one triangleHard-coded count in glDrawElements instead of the index count
Location -1Name typo, or unused variable optimized out
Uniform does nothingSet before glUseProgram, wrong setter type, location -1
Shape stretchedMissing aspect correction, or integer division
Shader pattern is an ellipseMath done in the aspect-corrected space
Translation ignored2D vertex z = 0 instead of 1
Rotation barely movesThis old glm rotate(mat3, angle) takes degrees unless GLM_FORCE_RADIANS
GLSL won’t compileConsole log; file missing from .qrc; assigning to an in
Crash on first gl callBefore initializeOpenGLFunctions() or outside a current context

OpenGL Hub · OpenGL API naming and call order · Undefined behavior · Exception handling