77. opengl.shader — OpenGL shader programs

Python OpenGL framework for pyFormex

This module is responsible for loading the shader programs and its data onto the graphics system.

  1. 2013 Benedict Verhegghe and the pyFormex project.
class opengl.shader.Shader(vshader=None, fshader=None, attributes=None, uniforms=None)[source]

An OpenGL shader consisting of a vertex and a fragment shader pair.

Class attributes:

  • _vertexshader : the vertex shader source. By default, a basic shader supporting vertex positions and vertex colors is defined
  • _fragmentshader : the fragment shader source. By default, a basic shader supporting fragment colors is defined.
  • attributes: the shaders’ vertex attributes.
  • uniforms: the shaders’ uniforms.
locations(func, keys)[source]

Create a dict with the locations of the specified keys

uniformInt(name, value)[source]

Load a uniform integer or boolean into the shader

uniformFloat(name, value)[source]

Load a uniform float into the shader

uniformVec3(name, value)[source]

Load a uniform vec3[n] into the shader

The value should be a 1D array or list.

uniformMat4(name, value)[source]

Load a uniform mat4 into the shader

uniformMat3(name, value)[source]

Load a uniform mat3 into the shader


Bind the shader program


Unbind the shader program


Load the uniform attributes defined in D

D is a dict with uniform attributes to be loaded into the shader program. The attributes can be of type int, float, or vec3.

77.1. Functions defined in module opengl.shader


Determine the default shader programs