OpenGL Context


class arcade.ArcadeContext(window: pyglet.window.BaseWindow, gc_mode: str = 'auto')[source]

An OpenGL context implementation for Arcade with added custom features. This context is normally accessed thought arcade.Window.ctx.

Pyglet users can use the base Context class and extend that as they please.

This is part of the low level rendering API in arcade and is mainly for more advanced usage

property default_atlas: arcade.texture_atlas.TextureAtlas

The default texture atlas. This is crated when arcade is initialized. All sprite lists will use use this atlas unless a different atlas is passned in the SpriteList constructor.



load_program(*, vertex_shader: Union[str, pathlib.Path], fragment_shader: Optional[Union[str, pathlib.Path]] = None, geometry_shader: Optional[Union[str, pathlib.Path]] = None, tess_control_shader: Optional[Union[str, pathlib.Path]] = None, tess_evaluation_shader: Optional[Union[str, pathlib.Path]] = None, defines: Optional[dict] = None)[source]

Create a new program given a file names that contain the vertex shader and fragment shader. Note that fragment and geometry shader are optional for when transform shaders are loaded.

This method also supports the :resources: prefix. It’s recommended to use absolute paths, but not required.


# The most common use case if having a vertex and fragment shader
program = window.ctx.load_program(
  • vertex_shader (Union[str,pathlib.Path]) – path to vertex shader

  • fragment_shader (Union[str,pathlib.Path]) – path to fragment shader (optional)

  • geometry_shader (Union[str,pathlib.Path]) – path to geometry shader (optional)

  • defines (dict) – Substitute #define values in the source

  • tess_control_shader (Union[str,pathlib.Path]) – Tessellation Control Shader

  • tess_evaluation_shader (Union[str,pathlib.Path]) – Tessellation Evaluation Shader

load_texture(path: Union[str, pathlib.Path], *, flip: bool = True, build_mipmaps=False)[source]

Loads and creates an OpenGL 2D texture. Currently all textures are converted to RGBA.


texture = window.ctx.load_texture("background.png")
  • path (Union[str,pathlib.Path]) – Path to texture

  • flip (bool) – Flips the image upside down

  • build_mipmaps (bool) – Build mipmaps for the texture

property projection_2d: Tuple[float, float, float, float]

Get or set the global orthogonal projection for arcade.

This projection is used by sprites and shapes and is represented by four floats: (left, right, bottom, top)


Tuple[float, float, float, float]

property projection_2d_matrix: arcade.math.Mat4

Get the current projection matrix. This 4x4 float32 matrix is calculated when setting projection_2d.




Context manager for pyglet rendering. Since arcade and pyglet needs slightly different states we needs some initialization and cleanup.


with window.ctx.pyglet_rendering():
    # Draw with pyglet here
reset() None[source]

Reset context flags and other states. This is mostly used in unit testing.