Shaders & programsGL 2.0

glCreateShader

Creates an empty shader object of a given stage.

Part of the family glCreate*

Signature

GLuint glCreateShader(GLenum shaderType);

How it works

A shader object holds the source and compiled code of ONE stage (vertex, fragment…). The workflow is always: create → set source → compile → check errors → attach to a program → link.

Unlike buffers, shaders are created directly with an ID return value, no glGen step.

Parameters

shaderTypeGLenum

Which pipeline stage this shader is for.

Common values

GL_VERTEX_SHADER
Runs once per vertex; outputs gl_Position.
GL_FRAGMENT_SHADER
Runs once per fragment (pixel candidate); outputs the color.
GL_GEOMETRY_SHADER
Optional: can emit or discard whole primitives.
GL_TESS_CONTROL_SHADER / GL_TESS_EVALUATION_SHADER
Optional tessellation stages (GL 4.0).
GL_COMPUTE_SHADER
General GPU computation outside the graphics pipeline (GL 4.3).

Return value

The new shader ID, or 0 if creation failed.

Errors

When the call is invalid it does nothing and sets an error, which glGetError returns:

GL_INVALID_ENUM
shaderType is not accepted.

Example

example.cpp
1GLuint vs = glCreateShader(GL_VERTEX_SHADER);
2glShaderSource(vs, 1, &vertexSrc, nullptr);
3glCompileShader(vs);
Official Khronos documentation