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.glOpenGL
pyglet.gl.gl.glext_arbARB registered OpenGL extension functions
pyglet.gl.gl.gl_compatDeprecated OpenGL extension functions.
These subpackages are also available, but are not imported into this namespace by default:
pyglet.gl.glext_nvnVidia OpenGL extension functions
pyglet.gl.aglAGL (Mac OS X OpenGL context functions)
pyglet.gl.glxGLX (Linux OpenGL context functions)
pyglet.gl.glxext_arbARB registered GLX extension functions
pyglet.gl.glxext_nvnvidia GLX extension functions
pyglet.gl.wglWGL (Windows OpenGL context functions)
pyglet.gl.wglext_arbARB registered WGL extension functions
pyglet.gl.wglext_nvnvidia WGL extension functions
The information modules are provided for convenience, and are documented below.
- exception GLException
- class Config
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.
- __init__(**kwargs: float) None
Create a template config with the given attributes.
Specify attributes as keyword arguments, for example:
template = Config(double_buffer=True)
- get_gl_attributes() list[tuple[str, bool | int | str]]
Return a list of attributes set on this config.
The attributes are returned as a list of tuples, containing the name and values. Any unset attributes will have a value of
None.
- is_complete() bool
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, DisplayConfig).- Return type:
- abstract match(
- canvas: Canvas,
Return a list of matching complete configs for the given canvas.
- Return type:
- GLDEBUGPROC
alias of
CFunctionType
- GLsync
alias of
LP_struct___GLsync
- class ObjectSpace
A container to store shared objects that are to be removed.
- class Config
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.
- __init__(**kwargs: float) None
Create a template config with the given attributes.
Specify attributes as keyword arguments, for example:
template = Config(double_buffer=True)
- get_gl_attributes() list[tuple[str, bool | int | str]]
Return a list of attributes set on this config.
The attributes are returned as a list of tuples, containing the name and values. Any unset attributes will have a value of
None.
- is_complete() bool
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, DisplayConfig).- Return type:
- abstract match(
- canvas: Canvas,
Return a list of matching complete configs for the given canvas.
- Return type:
- class DisplayConfig
-
An OpenGL configuration for a particular display.
Use
Config.matchto obtain an instance of this class.New in version 1.2.
- __init__( ) None
Create a template config with the given attributes.
Specify attributes as keyword arguments, for example:
template = Config(double_buffer=True)
- abstract create_context(
- share: Context,
Create a GL context that satisfies this configuration.
- is_complete() bool
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, DisplayConfig).- Return type:
- class Context
A base OpenGL context for drawing.
Use
DisplayConfig.create_contextto create a context.- __init__(
- config: DisplayConfig,
- context_share: Context | None = None,
Initialize a context.
This should only be created through the
DisplayConfig.create_contextmethod.- Parameters:
config (
DisplayConfig) – An operating system specific config.context_share (
Context|None) – A context to share objects with. UseNoneto disable sharing.
- create_program( ) ShaderProgram
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
ShaderPrograminstance.source_stringis OpenGL GLSL source code as a str, andshader_typeis the OpenGL shader type, such as “vertex” or “fragment”. SeeShaderfor more information. :rtype:ShaderProgramNote
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: int) None
Safely delete a Buffer belonging to this context’s object space.
This method behaves similarly to
delete_texture, though forglDeleteBuffersinstead ofglDeleteTextures.- Return type:
- delete_framebuffer(fbo_id: int) None
Safely delete a Framebuffer Object belonging to this context.
This method behaves similarly to
delete_vao, though forglDeleteFramebuffersinstead ofglDeleteVertexArrays.- Return type:
- delete_renderbuffer(rbo_id: int) None
Safely delete a Renderbuffer belonging to this context’s object space.
This method behaves similarly to
delete_texture, though forglDeleteRenderbuffersinstead ofglDeleteTextures.- Return type:
- delete_shader(shader_id: int) None
Safely delete a Shader belonging to this context’s object space.
This method behaves similarly to
delete_texture, though forglDeleteShaderinstead ofglDeleteTextures.- Return type:
- delete_shader_program(program_id: int) None
Safely delete a ShaderProgram belonging to this context’s object space.
This method behaves similarly to
delete_texture, though forglDeletePrograminstead ofglDeleteTextures.- Return type:
- delete_texture(texture_id: int) None
Safely delete a Texture belonging to this context’s object space.
This method will delete the texture immediately via
glDeleteTexturesif the current context’s object space is the same as this context’s object space, and it is called from the main thread.Otherwise, the texture will only be marked for deletion, postponing it until any context with the same object space becomes active again.
This makes it safe to call from anywhere, including other threads.
- Return type:
- delete_vao(vao_id: int) None
Safely delete a Vertex Array Object belonging to this context.
If this context is not the current context or this method is not called from the main thread, its deletion will be postponed until this context is next made active again.
Otherwise, this method will immediately delete the VAO via
glDeleteVertexArrays.- Return type:
- destroy() None
Release the Context.
The context will not be usable 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.
- Return type:
- get_info() GLInfo
Get the
GLInfoinstance for this context.- Return type:
GLInfo
- set_current() None
Make this the active Context.
Setting the Context current will also delete any OpenGL objects that have been queued for deletion. IE: any objects that were created in this Context, but have been called for deletion while another Context was active.
- Return type:
-
config:
DisplayConfig
-
object_space:
ObjectSpace A container which is shared between all contexts that share GL objects.