Skip to content
Back to top
View this page

# moderngl

    import moderngl

    window = ...
    ctx = moderngl.create_context()
    # store a ref to ctx

The module object itself is responsible for creating a `Context` object.

moderngl.create_context(require: int = 330, standalone: bool = False) → Context

  Create a ModernGL context by loading OpenGL functions from an existing OpenGL context. An OpenGL context must exist. Call this after a window is created or opt for the windowless standalone mode. Other backend specific settings are passed as keyword arguments.

  Context sharing is known to not work properly, please avoid using it. There is a paramter share for that to attempt to create a shared context.

  Parameters:

    - require (int) – OpenGL version code

    - standalone (bool) – Headless flag

  Example:

      # Accept the current context version
      ctx = moderngl.create_context()

      # Require at least OpenGL 4.3
      ctx = moderngl.create_context(require=430)

      # Create a windowless context
      ctx = moderngl.create_context(standalone=True)

moderngl.create_standalone_context(...) → Context

  Deprecated, use `moderngl.create_context()` with the standalone parameter set.

moderngl.get_context() → Context

  Returns the previously created context object.

  Example:

      # my_app.py

      from moderngl import create_context

      ctx = create_context(...)

      # my_renderer.py

      from moderngl import get_context

      class MyRenderer:
          def __init__(self):
              self.ctx = get_context()
              self.program = ...
              self.vao = ...

## Context Flags

These were moved to `Context`.

moderngl.NOTHING

  See `Context.NOTHING`

moderngl.BLEND

  See `Context.BLEND`

moderngl.DEPTH_TEST

  See `Context.DEPTH_TEST`

moderngl.CULL_FACE

  See `Context.CULL_FACE`

moderngl.RASTERIZER_DISCARD

  See `Context.RASTERIZER_DISCARD`

moderngl.PROGRAM_POINT_SIZE

  See `Context.PROGRAM_POINT_SIZE`

moderngl.POINTS

  See `Context.POINTS`

moderngl.LINES

  See `Context.LINES`

moderngl.LINE_LOOP

  See `Context.LINE_LOOP`

moderngl.LINE_STRIP

  See `Context.LINE_STRIP`

moderngl.TRIANGLES

  See `Context.TRIANGLES`

moderngl.TRIANGLE_STRIP

  See `Context.TRIANGLE_STRIP`

moderngl.TRIANGLE_FAN

  See `Context.TRIANGLE_FAN`

moderngl.LINES_ADJACENCY

  See `Context.LINES_ADJACENCY`

moderngl.LINE_STRIP_ADJACENCY

  See `Context.LINE_STRIP_ADJACENCY`

moderngl.TRIANGLES_ADJACENCY

  See `Context.TRIANGLES_ADJACENCY`

moderngl.TRIANGLE_STRIP_ADJACENCY

  See `Context.TRIANGLE_STRIP_ADJACENCY`

moderngl.PATCHES

  See `Context.PATCHES`

moderngl.NEAREST

  See `Context.NEAREST`

moderngl.LINEAR

  See `Context.LINEAR`

moderngl.NEAREST_MIPMAP_NEAREST

  See `Context.NEAREST_MIPMAP_NEAREST`

moderngl.LINEAR_MIPMAP_NEAREST

  See `Context.LINEAR_MIPMAP_NEAREST`

moderngl.NEAREST_MIPMAP_LINEAR

  See `Context.NEAREST_MIPMAP_LINEAR`

moderngl.LINEAR_MIPMAP_LINEAR

  See `Context.LINEAR_MIPMAP_LINEAR`

moderngl.ZERO

  See `Context.ZERO`

moderngl.ONE

  See `Context.ONE`

moderngl.SRC_COLOR

  See `Context.SRC_COLOR`

moderngl.ONE_MINUS_SRC_COLOR

  See `Context.ONE_MINUS_SRC_COLOR`

moderngl.SRC_ALPHA

  See `Context.SRC_ALPHA`

moderngl.ONE_MINUS_SRC_ALPHA

  See `Context.ONE_MINUS_SRC_ALPHA`

moderngl.DST_ALPHA

  See `Context.DST_ALPHA`

moderngl.ONE_MINUS_DST_ALPHA

  See `Context.ONE_MINUS_DST_ALPHA`

moderngl.DST_COLOR

  See `Context.DST_COLOR`

moderngl.ONE_MINUS_DST_COLOR

  See `Context.ONE_MINUS_DST_COLOR`

moderngl.DEFAULT_BLENDING

  See `Context.DEFAULT_BLENDING`

moderngl.ADDITIVE_BLENDING

  See `Context.ADDITIVE_BLENDING`

moderngl.PREMULTIPLIED_ALPHA

  See `Context.PREMULTIPLIED_ALPHA`

moderngl.FUNC_ADD

  See `Context.FUNC_ADD`

moderngl.FUNC_SUBTRACT

  See `Context.FUNC_SUBTRACT`

moderngl.FUNC_REVERSE_SUBTRACT

  See `Context.FUNC_REVERSE_SUBTRACT`

moderngl.MIN

  See `Context.MIN`

moderngl.MAX

  See `Context.MAX`

moderngl.FIRST_VERTEX_CONVENTION

  See `Context.FIRST_VERTEX_CONVENTION`

moderngl.LAST_VERTEX_CONVENTION

  See `Context.LAST_VERTEX_CONVENTION`