OpenGL and GLU interface.
This package imports all OpenGL, GLU and registered OpenGL extension functions. Functions have identical signatures to their C counterparts. For example:
from pyglet.gl import *
# [...omitted: set up a GL context and framebuffer]
glBegin(GL_QUADS)
glVertex3f(0, 0, 0)
glVertex3f(0.1, 0.2, 0.3)
glVertex3f(0.1, 0.2, 0.3)
glEnd()
OpenGL is documented in full at the OpenGL Reference Pages.
The OpenGL Programming Guide is a popular reference manual organised by topic. The free online version documents only OpenGL 1.1. Later editions cover more recent versions of the API and can be purchased from a book store.
The following subpackages are imported into this “mega” package already (and
so are available by importing pyglet.gl
):
pyglet.gl.gl
pyglet.gl.glu
pyglet.gl.gl.glext_arb
These subpackages are also available, but are not imported into this namespace by default:
pyglet.gl.glext_nv
pyglet.gl.agl
pyglet.gl.glx
pyglet.gl.glxext_arb
pyglet.gl.glxext_nv
pyglet.gl.wgl
pyglet.gl.wglext_arb
pyglet.gl.wglext_nv
The information modules are provided for convenience, and are documented below.
ConfigException
¶ContextException
¶get_current_context
()¶Return the active OpenGL context.
You can change the current context by calling Context.set_current.
Warning
Deprecated. Use current_context
Return type: | Context |
---|---|
Returns: | the context to which OpenGL commands are directed, or None if there is no selected context. |
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.
GLException
¶ObjectSpace
¶Config
(**kwargs)¶Graphics configuration.
A Config stores the preferences for OpenGL attributes such as the number of auxilliary 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.
Variables: |
|
---|
create_context
(share)¶Create a GL context that satisifies this configuration.
Warning
Deprecated. Use CanvasConfig.create_context.
Parameters: | share (Context) – 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.
Warning
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: | canvas (Canvas) – Display to host contexts created from the config. |
---|---|
Return type: | list of CanvasConfig |
debug
= None¶forward_compatible
= None¶major_version
= None¶minor_version
= None¶CanvasConfig
(canvas, base_config)¶Bases: pyglet.gl.base.Config
OpenGL configuration for a particular canvas.
Use Config.match to obtain an instance of this class.
New in version 1.2.
Variables: | canvas (Canvas) – The canvas this config is valid on. |
---|
compatible
(canvas)¶create_context
(share)¶Create a GL context that satisifies this configuration.
Parameters: | share (Context) – If not None, a context with which to share objects with. |
---|---|
Return type: | Context |
Returns: | The new context. |
is_complete
()¶Context
(config, context_share=None)¶OpenGL context for drawing.
Use CanvasConfig.create_context to create a context.
Variables: | object_space (ObjectSpace) – An object which is shared between all contexts that share GL objects. |
---|
attach
(canvas)¶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_id (int) – The OpenGL name of the buffer to delete. |
---|
New in version 1.1.
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_id (int) – The OpenGL name of the texture to delete. |
---|
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
()¶CONTEXT_SHARE_EXISTING
= 1¶Context share behaviour indicating that objects are shared with the most recently created context (the default).
CONTEXT_SHARE_NONE
= None¶Context share behaviour indicating that objects should not be shared with existing contexts.