moderngl_window.geometry

class moderngl_window.geometry.AttributeNames(position: str | None = None, normal: str | None = None, tangent: str | None = None, texcoord_0: str | None = None, texcoord_1: str | None = None, color_0: str | None = None, joints_0: str | None = None, weights: str | None = None, **kwargs: Any)[source]

Standard buffer/attribute names.

This works as a lookup for buffer names when creating VAO instances.

This class can be used directly or an instance of the class can be used with overrides. Optionally it can be extended into a new class.

COLOR_0 = 'in_color0'
JOINTS_0 = 'in_joints_0'
NORMAL = 'in_normal'
POSITION = 'in_position'
TANGENT = 'in_tangent'
TEXCOORD_0 = 'in_texcoord_0'
TEXCOORD_1 = 'in_texcoord_1'
WEIGHTS_0 = 'in_weights_0'
apply_values(kwargs: dict[str, Any]) None[source]

Only applies attribute values not None

moderngl_window.geometry.bbox(size: tuple[float, float, float] = (1.0, 1.0, 1.0), name: str | None = None, attr_names: type[~moderngl_window.geometry.attributes.AttributeNames] = <class 'moderngl_window.geometry.attributes.AttributeNames'>) VAO[source]

Generates a bounding box with (0.0, 0.0, 0.0) as the center. This is simply a box with LINE_STRIP as draw mode.

Keyword Arguments:
  • size (tuple) – x, y, z size of the box

  • name (str) – Optional name for the VAO

  • attr_names (AttributeNames) – Attribute names

Returns:

A moderngl_window.opengl.vao.VAO instance

moderngl_window.geometry.cube(size: tuple[float, float, float] = (1.0, 1.0, 1.0), center: tuple[float, float, float] = (0.0, 0.0, 0.0), normals: bool = True, uvs: bool = True, name: str | None = None, attr_names: type[~moderngl_window.geometry.attributes.AttributeNames] = <class 'moderngl_window.geometry.attributes.AttributeNames'>) VAO[source]

Creates a cube VAO with normals and texture coordinates

Keyword Arguments:
  • width (float) – Width of the cube

  • height (float) – Height of the cube

  • depth (float) – Depth of the cube

  • center – center of the cube as a 3-component tuple

  • normals – (bool) Include normals

  • uvs – (bool) include uv coordinates

  • name (str) – Optional name for the VAO

  • attr_names (AttributeNames) – Attribute names

Returns:

A moderngl_window.opengl.vao.VAO instance

moderngl_window.geometry.quad_2d(size: tuple[float, float] = (1.0, 1.0), pos: tuple[float, float] = (0.0, 0.0), normals: bool = True, uvs: bool = True, attr_names: type[~moderngl_window.geometry.attributes.AttributeNames] = <class 'moderngl_window.geometry.attributes.AttributeNames'>, name: str | None = None) VAO[source]

Creates a 2D quad VAO using 2 triangles with normals and texture coordinates.

Keyword Arguments:
  • size (tuple) – width and height

  • pos (float) – Center position x and y

  • normals (bool) – Include normals in VAO

  • uvs (bool) – Include texture coordinates in VAO

  • attr_names (AttributeNames) – Attrib name config

  • name (str) – Optional name for the VAO

Returns:

A VAO instance.

moderngl_window.geometry.quad_fs(attr_names: type[~moderngl_window.geometry.attributes.AttributeNames] = <class 'moderngl_window.geometry.attributes.AttributeNames'>, normals: bool = True, uvs: bool = True, name: str | None = None) VAO[source]

Creates a screen aligned quad using two triangles with normals and texture coordinates.

Keyword Arguments:
  • attr_names (AttributeNames) – Attrib name config

  • normals (bool) – Include normals in VAO

  • uvs (bool) – Include texture coordinates in VAO

  • name (str) – Optional name for the VAO

Returns:

A VAO instance.

moderngl_window.geometry.sphere(radius: float = 0.5, sectors: int = 32, rings: int = 16, normals: bool = True, uvs: bool = True, name: str | None = None, attr_names: type[~moderngl_window.geometry.attributes.AttributeNames] = <class 'moderngl_window.geometry.attributes.AttributeNames'>) VAO[source]

Creates a sphere.

Keyword Arguments:
  • radius (float) – Radius or the sphere

  • rings (int) – number or horizontal rings

  • sectors (int) – number of vertical segments

  • normals (bool) – Include normals in the VAO

  • uvs (bool) – Include texture coordinates in the VAO

  • name (str) – An optional name for the VAO

  • attr_names (AttributeNames) – Attribute names

Returns:

A VAO instance