moderngl¶
Attributes¶
Attributes available in the root moderngl
module.
Some may be listed in their original sub-module,
but they are imported during initialization.
Context Flags¶
Also available in the Context
instance
including mode details.
-
moderngl.context.
NOTHING
= 0¶ Represents no states. Can be used with
Context.enable_only()
to disable all states.
-
moderngl.context.
BLEND
= 1¶ Enable/disable blending
-
moderngl.context.
DEPTH_TEST
= 2¶ Enable/disable depth testing
-
moderngl.context.
CULL_FACE
= 4¶ Enable/disable face culling
-
moderngl.context.
RASTERIZER_DISCARD
= 8¶ Enable/disable rasterization
-
moderngl.context.
PROGRAM_POINT_SIZE
= 16¶ When enabled we can write to
gl_PointSize
in the vertex shader to specify the point size. When disabledContext.point_size
is used.
Primitive Modes¶
Also available in the Context
instance
including mode details.
-
moderngl.vertex_array.
POINTS
= 0¶ Each vertex represents a point
-
moderngl.vertex_array.
LINES
= 1¶ Vertices 0 and 1 are considered a line. Vertices 2 and 3 are considered a line. And so on. If the user specifies a non-even number of vertices, then the extra vertex is ignored.
-
moderngl.vertex_array.
LINE_LOOP
= 2¶ As line strips, except that the first and last vertices are also used as a line. Thus, you get n lines for n input vertices. If the user only specifies 1 vertex, the drawing command is ignored. The line between the first and last vertices happens after all of the previous lines in the sequence.
-
moderngl.vertex_array.
LINE_STRIP
= 3¶ The adjacent vertices are considered lines. Thus, if you pass n vertices, you will get n-1 lines. If the user only specifies 1 vertex, the drawing command is ignored.
-
moderngl.vertex_array.
TRIANGLES
= 4¶ Vertices 0, 1, and 2 form a triangle. Vertices 3, 4, and 5 form a triangle. And so on.
-
moderngl.vertex_array.
TRIANGLE_STRIP
= 5¶ Every group of 3 adjacent vertices forms a triangle. The face direction of the strip is determined by the winding of the first triangle. Each successive triangle will have its effective face order reversed, so the system compensates for that by testing it in the opposite way. A vertex stream of n length will generate n-2 triangles.
-
moderngl.vertex_array.
TRIANGLE_FAN
= 6¶ The first vertex is always held fixed. From there on, every group of 2 adjacent vertices form a triangle with the first. So with a vertex stream, you get a list of triangles like so: (0, 1, 2) (0, 2, 3), (0, 3, 4), etc. A vertex stream of n length will generate n-2 triangles.
-
moderngl.vertex_array.
LINES_ADJACENCY
= 10¶ These are special primitives that are expected to be used specifically with geomtry shaders. These primitives give the geometry shader more vertices to work with for each input primitive. Data needs to be duplicated in buffers.
-
moderngl.vertex_array.
LINE_STRIP_ADJACENCY
= 11¶ These are special primitives that are expected to be used specifically with geomtry shaders. These primitives give the geometry shader more vertices to work with for each input primitive. Data needs to be duplicated in buffers.
-
moderngl.vertex_array.
TRIANGLES_ADJACENCY
= 12¶ These are special primitives that are expected to be used specifically with geomtry shaders. These primitives give the geometry shader more vertices to work with for each input primitive. Data needs to be duplicated in buffers.
-
moderngl.vertex_array.
TRIANGLE_STRIP_ADJACENCY
= 13¶ These are special primitives that are expected to be used specifically with geomtry shaders. These primitives give the geometry shader more vertices to work with for each input primitive. Data needs to be duplicated in buffers.
-
moderngl.vertex_array.
PATCHES
= 14¶ primitive type can only be used when Tessellation is active. It is a primitive with a user-defined number of vertices, which is then tessellated based on the control and evaluation shaders into regular points, lines, or triangles, depending on the TES’s settings.
Texture Filters¶
Also available in the Context
instance
including mode details.
-
moderngl.texture.
NEAREST
= 9728¶ Returns the value of the texture element that is nearest (in Manhattan distance) to the specified texture coordinates.
-
moderngl.texture.
LINEAR
= 9729¶ Returns the weighted average of the four texture elements that are closest to the specified texture coordinates. These can include items wrapped or repeated from other parts of a texture, depending on the values of texture repeat mode, and on the exact mapping.
-
moderngl.texture.
NEAREST_MIPMAP_NEAREST
= 9984¶ Chooses the mipmap that most closely matches the size of the pixel being textured and uses the
NEAREST`
criterion (the texture element closest to the specified texture coordinates) to produce a texture value.
-
moderngl.texture.
LINEAR_MIPMAP_NEAREST
= 9985¶ Chooses the mipmap that most closely matches the size of the pixel being textured and uses the
LINEAR
criterion (a weighted average of the four texture elements that are closest to the specified texture coordinates) to produce a texture value.
-
moderngl.texture.
NEAREST_MIPMAP_LINEAR
= 9986¶ Chooses the two mipmaps that most closely match the size of the pixel being textured and uses the
NEAREST
criterion (the texture element closest to the specified texture coordinates ) to produce a texture value from each mipmap. The final texture value is a weighted average of those two values.
-
moderngl.texture.
LINEAR_MIPMAP_LINEAR
= 9987¶ Chooses the two mipmaps that most closely match the size of the pixel being textured and uses the
LINEAR
criterion (a weighted average of the texture elements that are closest to the specified texture coordinates) to produce a texture value from each mipmap. The final texture value is a weighted average of those two values.
Blend Functions¶
Also available in the Context
instance
including mode details.
-
moderngl.context.
ZERO
= 0¶ (0,0,0,0)
-
moderngl.context.
ONE
= 1¶ (1,1,1,1)
-
moderngl.context.
SRC_COLOR
= 768¶ (Rs0/kR,Gs0/kG,Bs0/kB,As0/kA)
-
moderngl.context.
ONE_MINUS_SRC_COLOR
= 769¶ (1,1,1,1) − (Rs0/kR,Gs0/kG,Bs0/kB,As0/kA)
-
moderngl.context.
SRC_ALPHA
= 770¶ (As0/kA,As0/kA,As0/kA,As0/kA)
-
moderngl.context.
ONE_MINUS_SRC_ALPHA
= 771¶ (1,1,1,1) − (As0/kA,As0/kA,As0/kA,As0/kA)
-
moderngl.context.
DST_ALPHA
= 772¶ (Ad/kA,Ad/kA,Ad/kA,Ad/kA)
-
moderngl.context.
ONE_MINUS_DST_ALPHA
= 773¶ (1,1,1,1) − (Ad/kA,Ad/kA,Ad/kA,Ad/kA)
-
moderngl.context.
DST_COLOR
= 774¶ (Rd/kR,Gd/kG,Bd/kB,Ad/kA)
-
moderngl.context.
ONE_MINUS_DST_COLOR
= 775¶ (1,1,1,1) − (Rd/kR,Gd/kG,Bd/kB,Ad/kA)
Shortcuts¶
-
moderngl.context.
DEFAULT_BLENDING
= (770, 771)¶ Shotcut for the default blending
SRC_ALPHA, ONE_MINUS_SRC_ALPHA
-
moderngl.context.
ADDITIVE_BLENDING
= (1, 1)¶ Shotcut for additive blending
ONE, ONE
-
moderngl.context.
PREMULTIPLIED_ALPHA
= (770, 1)¶ Shotcut for blend mode when using premultiplied alpha
SRC_ALPHA, ONE
Blend Equations¶
Also available in the Context
instance
including mode details.
-
moderngl.context.
FUNC_ADD
= 32774¶ source + destination
-
moderngl.context.
FUNC_SUBTRACT
= 32778¶ source - destination
-
moderngl.context.
FUNC_REVERSE_SUBTRACT
= 32779¶ destination - source
-
moderngl.context.
MIN
= 32775¶ Minimum of source and destination
-
moderngl.context.
MAX
= 32776¶ Maximum of source and destination
Provoking Vertex¶
Also available in the Context
instance
including mode details.
-
moderngl.context.
FIRST_VERTEX_CONVENTION
= 36429¶ Specifies the first vertex should be used as the source of data for flat shaded varyings. Used with
Context.provoking_vertex
.
-
moderngl.context.
LAST_VERTEX_CONVENTION
= 36430¶ Specifies the last vertex should be used as the source of data for flat shaded varyings. Used with
Context.provoking_vertex
.
Functions¶
Also see Context
.
-
moderngl.
create_context
(require=None, standalone=False, share=False, **settings) → moderngl.context.Context¶ Create a ModernGL context by loading OpenGL functions from an existing OpenGL context. An OpenGL context must exists.
Example:
# Accept the current context version ctx = moderngl.create_context() # Require at least OpenGL 4.3 ctx = moderngl.create_context(require=430) # Create a headless context requiring OpenGL 4.3 ctx = moderngl.create_context(require=430, standalone=True)
Keyword Arguments: - require (int) – OpenGL version code (default: 330)
- standalone (bool) – Headless flag
- **settings – Other backend specific settings
Returns: Context
object
-
moderngl.
create_standalone_context
(require=None, share=False, **settings) → moderngl.context.Context¶ Create a standalone/headless ModernGL context. The preferred way of making a context is through
moderngl.create_context()
.Example:
# Create a context with highest possible supported version ctx = moderngl.create_context() # Require at least OpenGL 4.3 ctx = moderngl.create_context(require=430)
Keyword Arguments: require (int) – OpenGL version code. Returns: Context
object