Shaders & programsGL 2.0

glCompileShader

Compiles the GLSL source stored in a shader object.

Signature

void glCompileShader(GLuint shader);

How it works

The driver's GLSL compiler turns your source into GPU code. The call itself never reports failure — a syntax error just leaves the shader in a failed state. You must ask with glGetShaderiv(GL_COMPILE_STATUS) and read the message with glGetShaderInfoLog.

Always check. Skipping it is why so many first triangles are silently black.

Parameters

shaderGLuint

The shader to compile.

Example

example.cpp
1glCompileShader(vs);
2GLint ok = GL_FALSE;
3glGetShaderiv(vs, GL_COMPILE_STATUS, &ok);
4if (!ok) {
5    char log[1024];
6    glGetShaderInfoLog(vs, sizeof(log), nullptr, log);
7    std::fprintf(stderr, "Vertex shader error:\n%s\n", log);
8}
Official Khronos documentation