psychopy.tools.gltools.compileShader

psychopy.tools.gltools.compileShader(shaderSrc, shaderType)[source]

Compile shader GLSL code and return a shader object. Shader objects can then be attached to programs an made executable on their respective processors.

Parameters:
  • shaderSrc (str, list of str) – GLSL shader source code.

  • shaderType (GLenum) – Shader program type (eg. GL_VERTEX_SHADER, GL_FRAGMENT_SHADER, GL_GEOMETRY_SHADER, etc.)

Returns:

OpenGL shader object handle retrieved from a glCreateShader call.

Return type:

int

Examples

Compiling GLSL source code and attaching it to a program object:

# GLSL vertex shader source
vertexSource =             '''
    #version 330 core
    layout (location = 0) in vec3 vertexPos;

    void main()
    {
        gl_Position = vec4(vertexPos, 1.0);
    }
    '''
# compile it, specifying `GL_VERTEX_SHADER`
vertexShader = compileShader(vertexSource, GL.GL_VERTEX_SHADER)
attachShader(myProgram, vertexShader)  # attach it to `myProgram`

Back to top