graphics: OpenGL

OpenGL classes

All calls to OpenGL are made through this module. Currently all OpenGL is done with PyOpenGL.

The Render class manages shader, view matrices, and lighting. The Buffer class handles object geometry (vertices, normals, triangles) and colors and texture coordinates. The Bindings class defines the connections between Buffers and shader program variables. The Texture class manages 2D texture storage.

class Bindings

Use an OpenGL vertex array object to save buffer bindings. The bindings are for a specific shader program since they use the shader variable ids.

activate()

Activate the bindings by binding the OpenGL vertex array object.

bind_shader_variable(buffer)

Bind the shader variable associated with buffer to the buffer data. This enables the OpenGL attribute array, and enables instancing if the buffer is instance data.

class Buffer(buffer_type)

Create an OpenGL buffer of vertex data such as vertex positions, normals, or colors, or per-instance data (e.g. color per sphere) or an element buffer for specifying which primitives (triangles, lines, points) to draw. Vertex data buffers can be attached to a specific shader variable.

delete_buffer()

Delete the OpenGL buffer object.

draw_elements(element_type=GL_TRIANGLES, ninst=None)

Draw primitives using this buffer as the element buffer. All the required buffers are assumed to be already bound using a vertex array object.

update_buffer_data(data)

Update the buffer with data supplied by a numpy array and bind it to the associated shader variable.

class Buffer_Type(shader_variable_name, buffer_type=GL_ARRAY_BUFFER, value_type=<class 'numpy.float32'>, normalize=False, instance_buffer=False, requires_capabilities=())

Describes a shader variable and the vertex buffer object value type required and what rendering capabilities are required to use this shader variable.

class Framebuffer(width=None, height=None, color=True, color_texture=None, depth=True, depth_texture=None)

OpenGL framebuffer for off-screen rendering. Allows rendering colors and/or depth to a texture.

class Render

Manage shaders, viewing matrices and lighting parameters to render a scene.

draw_background()

Draw the background color and clear the depth buffer.

draw_transparent(draw_depth, draw)

Render using single-layer transparency. This is a two-pass drawing. In the first pass is only sets the depth buffer, but not colors, and in the second path it draws the colors for pixels at or in front of the recorded depths. The draw_depth and draw routines, taking no arguments perform the actual drawing, and are invoked by this routine after setting the appropriate OpenGL color and depth drawing modes.

enable_blending(enable)

Enable OpenGL alpha blending.

enable_depth_test(enable)

Enable OpenGL depth testing.

frame_buffer_image(w, h, rgba=None)

Return the current frame buffer image as a numpy uint8 array of size (h,w,4) where w and h are the framebuffer width and height. The four components are red, green, blue, alpha. Array index 0,0 is at the bottom left corner of the OpenGL viewport.

initialize_opengl(width, height)

Create an initial vertex array object.

opengl_version()

String description of the OpenGL version for the current context.

set_background_color(rgba)

Set the OpenGL clear color.

set_model_matrix(model_matrix=None)

Set the shader model view using the given model matrix and previously set view matrix. If no matrix is specified, the shader gets the last used one model view matrix.

set_mono_buffer()

Set the draw and read buffers for mono rendering.

set_projection_matrix(pm=None)

Set the shader to use the given 4x4 OpenGL projection matrix. If no matrix is specified use the last specified one.

set_single_color(color=None)

Set the OpenGL shader color for shader single color mode.

set_stereo_buffer(eye_num)

Set the draw and read buffers for the left eye (0) or right eye (1).

set_view_matrix(vm)

Set the camera view matrix, mapping scene to camera coordinates.

set_viewport(x, y, w, h)

Set the OpenGL viewport.

shader(options)

Return a shader that supports the specified capabilities. The capabilities are specified as at bit field of values from SHADER_LIGHTING, SHADER_DEPTH_CUE, SHADER_TEXTURE_2D, SHADER_TEXTURE_3D_AMBIENT, SHADER_SHADOWS, SHADER_MULTISHADOW, SHADER_SHIFT_AND_SCALE, SHADER_INSTANCING, SHADER_TEXTURE_MASK, SHADER_DEPTH_OUTLINE, SHADER_VERTEX_COLORS

support_stereo()

Return if sequential stereo is supported.

use_shader(shader)

Set the current shader.

class Shader(capabilities)

OpenGL shader program with specified capabilities.

class Texture_Window(render, shader_options)

Draw a texture on a full window rectangle.

Table Of Contents

Previous topic

ui: Graphical user interface

Next topic

Chimera2 Web Application

This Page