Brain Dump

Shader Program

Tags
opengl

A collection of one or more shaders that must be enabled before it can be used in rendering.

Usage

We create a shader program much like a VBO.

unsigned int shaderProgram;
shaderProgram = glCreateProgram();

After creation you need to attach one or more shaders to the program.

// both vertexShader and fragmentShader are the ids of shaders
// we've already defined.
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);

Finally we need to link the shaders together in the program. This is effectively the same as compilation for a shader program.

glLinkProgram(shaderProgram);

Note: you can use the glGetProgramiv and glGetProgramInfoLog methods to check whether program linking failed.

We can use a newly made shader program like so:

glUseProgram(shaderProgram);

Links to this note