glUseProgram

Installs a program object as part of current rendering state

Signature

glUseProgram( GLuint ( program ) )-> void
glUseProgram( program )

Parameters

VariablesDescription
program
Specifies the handle of the program object whose executables are to be used as part of current rendering state.

Description

glUseProgram installs the program object specified by program as part of current rendering state. One or more executables are created in a program object by successfully attaching shader objects to it with glAttachShader , successfully compiling the shader objects with glCompileShader , and successfully linking the program object with glLinkProgram .
A program object will contain an executable that will run on the vertex processor if it contains one or more shader objects of type GL_VERTEX_SHADER that have been successfully compiled and linked. A program object will contain an executable that will run on the geometry processor if it contains one or more shader objects of type GL_GEOMETRY_SHADER that have been successfully compiled and linked. Similarly, a program object will contain an executable that will run on the fragment processor if it contains one or more shader objects of type GL_FRAGMENT_SHADER that have been successfully compiled and linked.
While a program object is in use, applications are free to modify attached shader objects, compile attached shader objects, attach additional shader objects, and detach or delete shader objects. None of these operations will affect the executables that are part of the current state. However, relinking the program object that is currently in use will install the program object as part of the current rendering state if the link operation was successful (see glLinkProgram ). If the program object currently in use is relinked unsuccessfully, its link status will be set to GL_FALSE , but the executables and associated state will remain part of the current state until a subsequent call to glUseProgram removes it from use. After it is removed from use, it cannot be made part of current state until it has been successfully relinked.
If program is zero, then the current rendering state refers to an invalid program object and the results of shader execution are undefined. However, this is not an error.
If program does not contain shader objects of type GL_FRAGMENT_SHADER , an executable will be installed on the vertex, and possibly geometry processors, but the results of fragment shader execution will be undefined.

Notes

Like buffer and texture objects, the name space for program objects may be shared across a set of contexts, as long as the server sides of the contexts share the same address space. If the name space is shared across contexts, any attached objects and the data associated with those attached objects are shared as well.
Applications are responsible for providing the synchronization across API calls when objects are accessed from different execution threads.

Errors

GL_INVALID_VALUE is generated if program is neither 0 nor a value generated by OpenGL.
GL_INVALID_OPERATION is generated if program is not a program object.
GL_INVALID_OPERATION is generated if program could not be made part of current state.
GL_INVALID_OPERATION is generated if transform feedback mode is active.

Associated Gets

glGet with the argument GL_CURRENT_PROGRAM
glGetActiveAttrib with a valid program object and the index of an active attribute variable
glGetActiveUniform with a valid program object and the index of an active uniform variable
glGetAttachedShaders with a valid program object
glGetAttribLocation with a valid program object and the name of an attribute variable
glGetProgram with a valid program object and the parameter to be queried
glGetProgramInfoLog with a valid program object
glGetUniform with a valid program object and the location of a uniform variable
glGetUniformLocation with a valid program object and the name of a uniform variable

Version Support

glUseProgram

See Also

Copyright

Copyright
2003-2005 3Dlabs Inc. Ltd. Copyright
2010-2014 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. .

Sample Code References

The following code samples have been found which appear to reference the functions described here. Take care that the code may be old, broken or not even use PyOpenGL.

glUseProgram
OpenGLContext OpenGLContext/scenegraph/shaders.py Lines: 441, 497, 537
OpenGLContext tests/shaders.py Lines: 26
OpenGLContext tests/shader_3.py Lines: 138, 177
OpenGLContext tests/shader_6.py Lines: 237, 321
OpenGLContext tests/shader_2.py Lines: 130, 191
OpenGLContext tests/pygame_textureatlas.py Lines: 125, 151
OpenGLContext tests/shader_4.py Lines: 117, 173
OpenGLContext tests/shader_2_c_void_p.py Lines: 55, 68
OpenGLContext tests/shader_11.py Lines: 264, 322
OpenGLContext tests/shader_7.py Lines: 279, 337
OpenGLContext tests/shader_5.py Lines: 288, 322
OpenGLContext tests/shader_9.py Lines: 345, 387
OpenGLContext tests/shader_10.py Lines: 294, 334
OpenGLContext tests/shader_8.py Lines: 213, 255
OpenGLContext tests/shader_4_subset.py Lines: 58, 78
OpenGLContext tests/shader_spike.py Lines: 13, 76, 91
OpenGLContext tests/shader_1.py Lines: 234, 278
OpenGL-Demo PyOpenGL-Demo/GLUT/shader_test.py Lines: 38, 88
OpenGL-Demo py2exe-example/shader_test.py Lines: 39, 89
{LGPL} PyMT pymt/graphx/shader.py Lines: 11, 79, 83
Gloopy gloopy/view/shader.py Lines: 34, 40
OpenGL Tutorial (Python Translation) t02.playing-with-colors/FragPosition.py Lines: 85, 93
OpenGL Tutorial (Python Translation) t02.playing-with-colors/VertexColors.py Lines: 88, 99
OpenGL Tutorial (Python Translation) t01.hello-triangle/HelloTriangle.py Lines: 99, 107
{GPL3} OpenGL-Programmable 05-shader.py Lines: 96
{GPL3} OpenGL-Programmable 07-attrib.py Lines: 113
{GPL3} OpenGL-Programmable 09-gles2.py Lines: 127
{GPL3} OpenGL-Programmable 06-perpixel.py Lines: 104
{GPL3} OpenGL-Programmable 10-gl3.2core.py Lines: 135
{GPL3} OpenGL-Programmable 08-pbo.py Lines: 113