Shaders & programsGL 2.0
glUseProgram
Selects the shader program used by the next draw calls.
Signature
void glUseProgram(GLuint program);
How it works
From now on, every draw runs this program's shaders. It also decides which program glUniform* calls write to — uniforms are set on the CURRENT program.
Parameters
programGLuint
A successfully linked program, or 0 for none.
Tips & pitfalls
Calling
glUniform* beforeglUseProgramsets the uniform on the wrong program (or fails). With OpenGL 4.1+glProgramUniform* avoids this.
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GL_INVALID_OPERATION
- program is not 0 and failed to link.
Example
example.cpp
1glUseProgram(program);
2glUniformMatrix4fv(glGetUniformLocation(program, "model"), 1, GL_FALSE, &model[0][0]);
3glBindVertexArray(vao);
4glDrawArrays(GL_TRIANGLES, 0, 36);