pyglet.gl

OpenGL interface.

This package imports all OpenGL and registered OpenGL extension functions. Functions have identical signatures to their C counterparts.

OpenGL is documented in full at the OpenGL Reference Pages.

The OpenGL Programming Guide, also known as “The Red Book”, is a popular reference manual organised by topic. It is available in digital and paper editions.

The following subpackages are imported into this “mega” package already (and so are available by importing pyglet.gl):

pyglet.gl.gl

OpenGL

pyglet.gl.gl.glext_arb

ARB registered OpenGL extension functions

These subpackages are also available, but are not imported into this namespace by default:

pyglet.gl.glext_nv

nVidia OpenGL extension functions

pyglet.gl.agl

AGL (Mac OS X OpenGL context functions)

pyglet.gl.glx

GLX (Linux OpenGL context functions)

pyglet.gl.glxext_arb

ARB registered GLX extension functions

pyglet.gl.glxext_nv

nvidia GLX extension functions

pyglet.gl.wgl

WGL (Windows OpenGL context functions)

pyglet.gl.wglext_arb

ARB registered WGL extension functions

pyglet.gl.wglext_nv

nvidia WGL extension functions

The information modules are provided for convenience, and are documented below.

exception ConfigException
exception ContextException
current_context = None

The active OpenGL context.

You can change the current context by calling Context.set_current; do not modify this global.

Type

Context

New in version 1.1.

class GLException
class ObjectSpace
class Config(**kwargs)

Graphics configuration.

A Config stores the preferences for OpenGL attributes such as the number of auxiliary buffers, size of the colour and depth buffers, double buffering, stencilling, multi- and super-sampling, and so on.

Different platforms support a different set of attributes, so these are set with a string key and a value which is integer or boolean.

Ivariables
double_bufferbool

Specify the presence of a back-buffer for every color buffer.

stereobool

Specify the presence of separate left and right buffer sets.

buffer_sizeint

Total bits per sample per color buffer.

aux_buffersint

The number of auxiliary color buffers.

sample_buffersint

The number of multisample buffers.

samplesint

The number of samples per pixel, or 0 if there are no multisample buffers.

red_sizeint

Bits per sample per buffer devoted to the red component.

green_sizeint

Bits per sample per buffer devoted to the green component.

blue_sizeint

Bits per sample per buffer devoted to the blue component.

alpha_sizeint

Bits per sample per buffer devoted to the alpha component.

depth_sizeint

Bits per sample in the depth buffer.

stencil_sizeint

Bits per sample in the stencil buffer.

accum_red_sizeint

Bits per pixel devoted to the red component in the accumulation buffer.

accum_green_sizeint

Bits per pixel devoted to the green component in the accumulation buffer.

accum_blue_sizeint

Bits per pixel devoted to the blue component in the accumulation buffer.

accum_alpha_sizeint

Bits per pixel devoted to the alpha component in the accumulation buffer.

create_context(share)

Create a GL context that satisifies this configuration.

Deprecated

Use CanvasConfig.create_context.

Parameters
shareContext

If not None, a context with which to share objects with.

Return type

Context

Returns

The new context.

get_gl_attributes()

Return a list of attributes set on this config.

Return type

list of tuple (name, value)

Returns

All attributes, with unset attributes having a value of None.

is_complete()

Determine if this config is complete and able to create a context.

Configs created directly are not complete, they can only serve as templates for retrieving a supported config from the system. For example, pyglet.window.Screen.get_matching_configs returns complete configs.

Deprecated

Use isinstance(config, CanvasConfig).

Return type

bool

Returns

True if the config is complete and can create a context.

match(canvas)

Return a list of matching complete configs for the given canvas.

New in version 1.2.

Parameters
canvasCanvas

Display to host contexts created from the config.

Return type

list of CanvasConfig

debug = None
forward_compatible = None
major_version = None
minor_version = None
opengl_api = None
class CanvasConfig(canvas, base_config)

Bases: Config

An OpenGL configuration for a particular canvas.

Use Config.match to obtain an instance of this class.

New in version 1.2.

Ivariables
canvasCanvas

The canvas this config is valid on.

compatible(canvas)
create_context(share)

Create a GL context that satisifies this configuration.

Parameters
shareContext

If not None, a context with which to share objects with.

Return type

Context

Returns

The new context.

is_complete()

Determine if this config is complete and able to create a context.

Configs created directly are not complete, they can only serve as templates for retrieving a supported config from the system. For example, pyglet.window.Screen.get_matching_configs returns complete configs.

Deprecated

Use isinstance(config, CanvasConfig).

Return type

bool

Returns

True if the config is complete and can create a context.

class Context(config, context_share=None)

An OpenGL context for drawing.

Use CanvasConfig.create_context to create a context.

Ivariables
object_spaceObjectSpace

An object which is shared between all contexts that share GL objects.

attach(canvas)
create_program(*sources: Tuple[str, str], program_class=None)

Create a ShaderProgram from OpenGL GLSL source.

This is a convenience method that takes one or more tuples of (source_string, shader_type), and returns a ShaderProgram instance.

source_string is OpenGL GLSL source code as a str, and shader_type is the OpenGL shader type, such as “vertex” or “fragment”. See Shader for more information.

Note

This method is cached. Given the same shader sources, the same ShaderProgram instance will be returned. For more control over the ShaderProgram lifecycle, it is recommended to manually create Shaders and link ShaderPrograms.

New in version 2.0.10.

delete_buffer(buffer_id)

Safely delete a Buffer object belonging to this context.

This method behaves similarly to delete_texture, though for glDeleteBuffers instead of glDeleteTextures.

Parameters
buffer_idint

The OpenGL name of the buffer to delete.

New in version 1.1.

delete_shader_program(program_id)

Safely delete a Shader Program belonging to this context.

This method behaves similarly to delete_texture, though for glDeleteProgram instead of glDeleteTextures.

Parameters
program_idint

The OpenGL name of the Shader Program to delete.

New in version 2.0.

delete_texture(texture_id)

Safely delete a Texture belonging to this context.

Usually, the Texture is released immediately using glDeleteTextures, however if another context that does not share this context’s object space is currently active, the deletion will be deferred until an appropriate context is activated.

Parameters
texture_idint

The OpenGL name of the Texture to delete.

delete_vao(vao_id)

Safely delete a Vertex Array Object belonging to this context.

This method behaves similarly to delete_texture, though for glDeleteVertexArrays instead of glDeleteTextures.

Parameters
vao_idint

The OpenGL name of the Vertex Array to delete.

New in version 2.0.

destroy()

Release the context.

The context will not be useable after being destroyed. Each platform has its own convention for releasing the context and the buffer(s) that depend on it in the correct order; this should never be called by an application.

detach()
get_info()

Get the OpenGL information for this context.

New in version 1.2.

Return type

GLInfo

set_current()