psychopy.tools.gltools

OpenGL related helper functions.

Shaders

Tools for creating, compiling, using, and inspecting shader programs.

createProgram()

Create an empty program object for shaders.

createProgramObjectARB()

Create an empty program object for shaders.

compileShader(shaderSrc, shaderType)

Compile shader GLSL code and return a shader object.

compileShaderObjectARB(shaderSrc, shaderType)

Compile shader GLSL code and return a shader object.

embedShaderSourceDefs(shaderSrc, defs)

Embed preprocessor definitions into GLSL source code.

deleteObject(obj)

Delete a shader or program object.

deleteObjectARB(obj)

Delete a program or shader object.

attachShader(program, shader)

Attach a shader to a program.

attachObjectARB(program, shader)

Attach a shader object to a program.

detachShader(program, shader)

Detach a shader object from a program.

detachObjectARB(program, shader)

Detach a shader object from a program.

linkProgram(program)

Link a shader program.

linkProgramObjectARB(program)

Link a shader program object.

validateProgram(program)

Check if the program can execute given the current OpenGL state.

validateProgramARB(program)

Check if the program can execute given the current OpenGL state.

useProgram(program)

Use a program object's executable shader attachments in the current OpenGL rendering state.

useProgramObjectARB(program)

Use a program object's executable shader attachments in the current OpenGL rendering state.

getInfoLog(obj)

Get the information log from a shader or program.

getUniformLocations(program[, builtins])

Get uniform names and locations from a given shader program object.

getAttribLocations(program[, builtins])

Get attribute names and locations from the specified program object.

Query

Tools for using OpenGL query objects.

createQueryObject([target])

Create a GL query object.

QueryObjectInfo(name, target)

Object for querying information.

beginQuery(query)

Begin query.

endQuery(query)

End a query.

getQuery(query)

Get the value stored in a query object.

getAbsTimeGPU()

Get the absolute GPU time in nanoseconds.

Framebuffer Objects (FBO)

Tools for creating Framebuffer Objects (FBOs).

createFBO([attachments])

Create a Framebuffer Object.

attach(attachPoint, imageBuffer)

Attach an image to a specified attachment point on the presently bound FBO.

isComplete()

Check if the currently bound framebuffer is complete.

deleteFBO(fbo)

Delete a framebuffer.

blitFBO(srcRect[, dstRect, filter])

Copy a block of pixels between framebuffers via blitting.

useFBO(fbo)

Context manager for Framebuffer Object bindings.

Renderbuffers

Tools for creating Renderbuffers.

createRenderbuffer(width, height[, ...])

Create a new Renderbuffer Object with a specified internal format.

deleteRenderbuffer(renderBuffer)

Free the resources associated with a renderbuffer.

Textures

Tools for creating textures.

createTexImage2D(width, height[, target, ...])

Create a 2D texture in video memory.

createTexImage2dFromFile(imgFile[, transpose])

Load an image from file directly into a texture.

createTexImage2DMultisample(width, height[, ...])

Create a 2D multisampled texture.

deleteTexture(texture)

Free the resources associated with a texture.

bindTexture(texture[, unit, enable])

Bind a texture.

unbindTexture([texture])

Unbind a texture.

createCubeMap(width, height[, target, ...])

Create a cubemap.

Vertex Buffer/Array Objects

Tools for creating and working with Vertex Buffer Objects (VBOs) and Vertex Array Objects (VAOs).

VertexArrayInfo([name, count, ...])

Vertex array object (VAO) descriptor.

createVAO(attribBuffers[, indexBuffer, ...])

Create a Vertex Array object (VAO).

drawVAO(vao[, mode, start, count, ...])

Draw a vertex array object.

deleteVAO(vao)

Delete a Vertex Array Object (VAO).

VertexBufferInfo([name, target, usage, ...])

Vertex buffer object (VBO) descriptor.

createVBO(data[, target, dataType, usage])

Create an array buffer object (VBO).

bindVBO(vbo)

Bind a VBO to the current GL state.

unbindVBO(vbo)

Unbind a vertex buffer object (VBO).

mapBuffer(vbo[, start, length, read, write, ...])

Map a vertex buffer object to client memory.

unmapBuffer(vbo)

Unmap a previously mapped buffer.

deleteVBO(vbo)

Delete a vertex buffer object (VBO).

setVertexAttribPointer(index, vbo[, size, ...])

Define an array of vertex attribute data with a VBO descriptor.

enableVertexAttribArray(index[, legacy])

Enable a vertex attribute array.

disableVertexAttribArray(index[, legacy])

Disable a vertex attribute array.

Materials and Lighting

Tools for specifying the appearance of faces and shading. Note that these tools use the legacy OpenGL pipeline which may not be available on your platform. Use fragment/vertex shaders instead for newer applications.

createMaterial([params, textures, face])

Create a new material.

useMaterial(material[, useTextures])

Use a material for proceeding vertex draws.

createLight([params])

Create a point light source.

useLights(lights[, setupOnly])

Use specified lights in successive rendering operations.

setAmbientLight(color)

Set the global ambient lighting for the scene when lighting is enabled.

Meshes

Tools for loading or procedurally generating meshes (3D models).

ObjMeshInfo([vertexPos, texCoords, normals, ...])

Descriptor for mesh data loaded from a Wavefront OBJ file.

loadObjFile(objFile)

Load a Wavefront OBJ file (*.obj).

loadMtlFile(mtllib[, texParams])

Load a material library file (*.mtl).

createUVSphere([radius, sectors, stacks, ...])

Create a UV sphere.

createPlane([size])

Create a plane.

createMeshGridFromArrays(xvals, yvals[, ...])

Create a mesh grid using coordinates from arrays.

createMeshGrid([size, subdiv, tessMode])

Create a grid mesh.

createBox([size, flipFaces])

Create a box mesh.

transformMeshPosOri(vertices, normals[, ...])

Transform a mesh.

calculateVertexNormals(vertices, faces[, ...])

Calculate vertex normals given vertices and triangle faces.

Miscellaneous

Miscellaneous tools for working with OpenGL.

getIntegerv(parName)

Get a single integer parameter value, return it as a Python integer.

getFloatv(parName)

Get a single float parameter value, return it as a Python float.

getString(parName)

Get a single string parameter value, return it as a Python UTF-8 string.

getOpenGLInfo()

Get general information about the OpenGL implementation on this machine.

getModelViewMatrix()

Get the present model matrix from the OpenGL matrix stack.

getProjectionMatrix()

Get the present projection matrix from the OpenGL matrix stack.

Examples

Working with Framebuffer Objects (FBOs):

Creating an empty framebuffer with no attachments:

fbo = createFBO()  # invalid until attachments are added

Create a render target with multiple color texture attachments:

colorTex = createTexImage2D(1024,1024)  # empty texture
depthRb = createRenderbuffer(800,600,internalFormat=GL.GL_DEPTH24_STENCIL8)

GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, fbo.id)
attach(GL.GL_COLOR_ATTACHMENT0, colorTex)
attach(GL.GL_DEPTH_ATTACHMENT, depthRb)
attach(GL.GL_STENCIL_ATTACHMENT, depthRb)
# or attach(GL.GL_DEPTH_STENCIL_ATTACHMENT, depthRb)
GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0)

Attach FBO images using a context. This automatically returns to the previous FBO binding state when complete. This is useful if you don’t know the current binding state:

with useFBO(fbo):
    attach(GL.GL_COLOR_ATTACHMENT0, colorTex)
    attach(GL.GL_DEPTH_ATTACHMENT, depthRb)
    attach(GL.GL_STENCIL_ATTACHMENT, depthRb)

How to set userData some custom function might access:

fbo.userData['flags'] = ['left_eye', 'clear_before_use']

Binding an FBO for drawing/reading:

GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, fb.id)

Depth-only framebuffers are valid, sometimes need for generating shadows:

depthTex = createTexImage2D(800, 600,
                            internalFormat=GL.GL_DEPTH_COMPONENT24,
                            pixelFormat=GL.GL_DEPTH_COMPONENT)
fbo = createFBO([(GL.GL_DEPTH_ATTACHMENT, depthTex)])

Deleting a framebuffer when done with it. This invalidates the framebuffer’s ID and makes it available for use:

deleteFBO(fbo)

Back to top