psychopy.tools.gltools.createProgram

psychopy.tools.gltools.createProgram()[source]

Create an empty program object for shaders.

Returns:

OpenGL program object handle retrieved from a glCreateProgram call.

Return type:

int

Examples

Building a program with vertex and fragment shader attachments:

myProgram = createProgram()  # new shader object

# compile vertex and fragment shader sources
vertexShader = compileShader(vertShaderSource, GL.GL_VERTEX_SHADER)
fragmentShader = compileShader(fragShaderSource, GL.GL_FRAGMENT_SHADER)

# attach shaders to program
attachShader(myProgram, vertexShader)
attachShader(myProgram, fragmentShader)

# link the shader, makes `myProgram` attachments executable by their
# respective processors and available for use
linkProgram(myProgram)

# optional, validate the program
validateProgram(myProgram)

# optional, detach and discard shader objects
detachShader(myProgram, vertexShader)
detachShader(myProgram, fragmentShader)

deleteObject(vertexShader)
deleteObject(fragmentShader)

You can install the program for use in the current rendering state by calling:

useProgram(myShader) # OR glUseProgram(myShader)
# set uniforms/attributes and start drawing here ...

Back to top