Shaders & programsGL 2.0

glGetShaderInfoLog

Reads the compiler's error and warning messages for a shader.

Part of the family glGet*

Signature

void glGetShaderInfoLog(GLuint shader, GLsizei maxLength,
                        GLsizei *length, GLchar *infoLog);

How it works

When compilation fails, this is where the explanation is — with line numbers, like "0:12: 'vec' : undeclared identifier". The format varies between vendors, but the line number is almost always there.

Parameters

shaderGLuint

Shader whose log to read.

maxLengthGLsizei

Size of your infoLog buffer.

lengthGLsizei *

Receives the number of characters written (optional, may be nullptr).

infoLogGLchar *

Buffer that receives the text.

Example

example.cpp
1char log[1024];
2glGetShaderInfoLog(shader, sizeof(log), nullptr, log);
3std::fprintf(stderr, "%s\n", log);
Official Khronos documentation