psychopy.tools.gltools
¶OpenGL related helper functions.
Tools for creating, compiling, using, and inspecting shader programs.
Create an empty program object for shaders. |
|
Create an empty program object for shaders. |
|
|
Compile shader GLSL code and return a shader object. |
|
Compile shader GLSL code and return a shader object. |
|
Embed preprocessor definitions into GLSL source code. |
|
Delete a shader or program object. |
|
Delete a program or shader object. |
|
Attach a shader to a program. |
|
Attach a shader object to a program. |
|
Detach a shader object from a program. |
|
Detach a shader object from a program. |
|
Link a shader program. |
|
Link a shader program object. |
|
Check if the program can execute given the current OpenGL state. |
|
Check if the program can execute given the current OpenGL state. |
|
Use a program object's executable shader attachments in the current OpenGL rendering state. |
|
Use a program object's executable shader attachments in the current OpenGL rendering state. |
|
Get the information log from a shader or program. |
|
Get uniform names and locations from a given shader program object. |
|
Get attribute names and locations from the specified program object. |
Tools for using OpenGL query objects.
|
Create a GL query object. |
|
Object for querying information. |
|
Begin query. |
|
End a query. |
|
Get the value stored in a query object. |
Get the absolute GPU time in nanoseconds. |
Tools for creating Framebuffer Objects (FBOs).
|
Create a Framebuffer Object. |
|
Attach an image to a specified attachment point on the presently bound FBO. |
Check if the currently bound framebuffer is complete. |
|
|
Delete a framebuffer. |
|
Copy a block of pixels between framebuffers via blitting. |
|
Context manager for Framebuffer Object bindings. |
Tools for creating Renderbuffers.
|
Create a new Renderbuffer Object with a specified internal format. |
|
Free the resources associated with a renderbuffer. |
Tools for creating textures.
|
Create a 2D texture in video memory. |
|
Load an image from file directly into a texture. |
|
Create a 2D multisampled texture. |
|
Free the resources associated with a texture. |
|
Bind a texture. |
|
Unbind a texture. |
|
Create a cubemap. |
Tools for creating and working with Vertex Buffer Objects (VBOs) and Vertex Array Objects (VAOs).
|
Vertex array object (VAO) descriptor. |
|
Create a Vertex Array object (VAO). |
|
Draw a vertex array object. |
|
Delete a Vertex Array Object (VAO). |
|
Vertex buffer object (VBO) descriptor. |
|
Create an array buffer object (VBO). |
|
Bind a VBO to the current GL state. |
|
Unbind a vertex buffer object (VBO). |
|
Map a vertex buffer object to client memory. |
|
Unmap a previously mapped buffer. |
|
Delete a vertex buffer object (VBO). |
|
Define an array of vertex attribute data with a VBO descriptor. |
|
Enable a vertex attribute array. |
|
Disable a vertex attribute array. |
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.
|
Create a new material. |
|
Use a material for proceeding vertex draws. |
|
Create a point light source. |
|
Use specified lights in successive rendering operations. |
|
Set the global ambient lighting for the scene when lighting is enabled. |
Tools for loading or procedurally generating meshes (3D models).
|
Descriptor for mesh data loaded from a Wavefront OBJ file. |
|
Load a Wavefront OBJ file (*.obj). |
|
Load a material library file (*.mtl). |
|
Create a UV sphere. |
|
Create a plane. |
|
Create a mesh grid using coordinates from arrays. |
|
Create a grid mesh. |
|
Create a box mesh. |
|
Transform a mesh. |
|
Calculate vertex normals given vertices and triangle faces. |
Miscellaneous tools for working with OpenGL.
|
Get a single integer parameter value, return it as a Python integer. |
|
Get a single float parameter value, return it as a Python float. |
|
Get a single string parameter value, return it as a Python UTF-8 string. |
Get general information about the OpenGL implementation on this machine. |
|
Get the present model matrix from the OpenGL matrix stack. |
|
Get the present projection matrix from the OpenGL matrix stack. |
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)