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#
- moderngl.CULL_FACE#
- moderngl.RASTERIZER_DISCARD#
- moderngl.PROGRAM_POINT_SIZE#
- moderngl.POINTS#
See
Context.POINTS
- moderngl.LINES#
See
Context.LINES
- moderngl.LINE_LOOP#
- moderngl.LINE_STRIP#
- moderngl.TRIANGLES#
- moderngl.TRIANGLE_STRIP#
- moderngl.TRIANGLE_FAN#
- moderngl.LINES_ADJACENCY#
- moderngl.LINE_STRIP_ADJACENCY#
- moderngl.TRIANGLES_ADJACENCY#
- moderngl.TRIANGLE_STRIP_ADJACENCY#
- moderngl.PATCHES#
See
Context.PATCHES
- moderngl.NEAREST#
See
Context.NEAREST
- moderngl.LINEAR#
See
Context.LINEAR
- moderngl.NEAREST_MIPMAP_NEAREST#
- moderngl.LINEAR_MIPMAP_NEAREST#
- moderngl.NEAREST_MIPMAP_LINEAR#
- moderngl.LINEAR_MIPMAP_LINEAR#
- moderngl.ZERO#
See
Context.ZERO
- moderngl.ONE#
See
Context.ONE
- moderngl.SRC_COLOR#
- moderngl.ONE_MINUS_SRC_COLOR#
- moderngl.SRC_ALPHA#
- moderngl.ONE_MINUS_SRC_ALPHA#
- moderngl.DST_ALPHA#
- moderngl.ONE_MINUS_DST_ALPHA#
- moderngl.DST_COLOR#
- moderngl.ONE_MINUS_DST_COLOR#
- moderngl.DEFAULT_BLENDING#
- moderngl.ADDITIVE_BLENDING#
- moderngl.PREMULTIPLIED_ALPHA#
- moderngl.FUNC_ADD#
See
Context.FUNC_ADD
- moderngl.FUNC_SUBTRACT#
- moderngl.FUNC_REVERSE_SUBTRACT#
- moderngl.MIN#
See
Context.MIN
- moderngl.MAX#
See
Context.MAX
- moderngl.FIRST_VERTEX_CONVENTION#
- moderngl.LAST_VERTEX_CONVENTION#