Introduction
Pyglet is a simple yet powerful library for creating aesthetically rich GUI programs on Windows, Mac OS, and Linux, such as games and multimedia. This Python-only package includes capabilities such as windowing, user interface event management, joysticks, OpenGL graphics, loading photos and movies, and playing sounds and music. Pyglet is released under the BSD open-source licence, which allows it to be used in both commercial and open-source projects with few restrictions. The article explains the details of the pyglet.graphics.vertexdomain module, different classes of pyglet.graphics.vertexdomain, along with its predefined functions.
pyglet.graphics.vertexdomain
A vertex "domain" is made up of a collection of attribute descriptions that describe the layout of one or more vertex buffers used to specify the vertices in a primitive. Furthermore, the domain is in charge of the data buffers, which it will resize as needed to accommodate new vertices.
Domains can be indexed if desired, in which case they handle a buffer of vertex indices. This buffer is grown independently of the attribute buffers and has no size relationship with them. The VertexDomain.create() method allows applications to construct vertices (and optionally indices) within a domain. The list of vertices generated is represented by a VertexList. The group's vertex attribute data can be changed, and the changes will be reflected in the underlying buffers automatically. If all of the vertices are primitives of the same OpenGL primitive mode, the VertexDomain.draw() method can efficiently draw the entire domain in one phase.
Let's have a detailed discussion on the various classes and methods of pyglet.graphics.vertexdomain.
classIndexedVertexDomain(attribute_usages, index_gl_type=5125)
Managing a collection of indexed vertex lists. The create_indexed_domain function is commonly used to construct an indexed vertex domain.
create(count, index_count)
In this domain, an IndexedVertexList is created.
Parameters:
- count (int) – Number of vertices to create
- index_count – Number of indices to create
draw(mode, vertex_list=None)
It is used to draw the domain's vertices.
All vertices in the domain are drawn if vertex_list is not given. This is the fastest method for rendering primitives. Only primitives in the VertexList specified by vertex_list will be rendered.
Parameters:
- mode (int) – OpenGL drawing mode, Example, GL_POINTS, GL_LINES, etc.
- vertex_list (IndexedVertexList) – Vertex list to draw, or None for all lists in this domain.
get_index_region(start, count)
It is used to get a region of the index buffer.
Parameters:
- start (int) – Start the region to map.
- count (int) – Number of indices to map.
Return type:
Array of int
classIndexedVertexList(domain, start, count, index_start, index_count)
An IndexedVertexDomain has a list of indexed vertices. IndexedVertexDomain should be used. To make this list, use create().
delete()
Delete this group.
draw(mode)
Draw this vertex list in the OpenGL mode specified.
Parameters:
- mode (int) – OpenGL drawing mode, e.g. GL_POINTS, GL_LINES, etc.
migrate(domain)
This group should be moved from its current indexed domain to the one supplied. Domain attributes must match.
Parameters:
- domain (IndexedVertexDomain) – Indexed domain to migrate this vertex list to.
resize(count, index_count)
It is used to resize this group.
Parameters:
- count (int) – New number of vertices in the list.
- index_count (int) – New number of indices in the list.
indices
It is the array of index data.
classVertexDomain(attribute_usages)
A set of vertex lists is managed.
The create_domain() function is commonly used to create a vertex domain.
create(count)
It is used to create a VertexList in this domain.
Parameters:
- count (int) – Number of vertices to create.
Return type: VertexList
draw(mode, vertex_list=None)
It is used to draw the domain's vertices. All vertices in the domain are drawn if the vertex list is not given. This is the fastest method for rendering primitives.
Only primitives in the VertexList specified by vertex list will be rendered.
Parameters:
- mode (int) – OpenGL drawing mode, e.g., GL_POINTS, GL_LINES, etc.
- vertex_list (VertexList) – Vertex list to draw, or None for all lists in this domain.
classVertexList(domain, start, count)
Within a VertexDomain, It is a list of vertices. Use VertexDomain instead. To make this list, use create().
delete()
Delete this group.
draw(mode)
Draw this vertex list in the OpenGL mode specified.
Parameters:
- mode (int) – OpenGL drawing mode, e.g. GL_POINTS, GL_LINES, etc.
get_domain()
Retrieve the domain to which this vertex list belongs.
Return type: VertexDomain
get_size()
Find out how many vertices there are in the list.
Return type: int
migrate(domain)
This group will be moved from its current domain to the one chosen. Domain attributes must match.
Parameters:
- domain (VertexDomain) – Domain to migrate this vertex list to.
resize(count)
Resize this group.
Parameters:
- count (int) – New number of vertices in the list.
colors
Array of color data.
edge_flags
Array of edge flag data.
fog_coords
Array of fog coordinate data.
multi_tex_coords
Multi-array texture coordinate data.
normals
Array of normal vector data.
secondary_colors
Array of secondary color data.
tex_coords
Array of texture coordinate data.
vertices
Array of vertex coordinate data.
create_attribute_usage(fmt)
From a format string, it is used to create an attribute and usage pair. The format string is the same as pyglet.graphics.vertexattribute, except with the addition of a usage component:
usage ::= attribute ( '/' ('static' | 'dynamic' | 'stream' | 'none') )?
If no usage is specified, the default is 'dynamic.' The usage matches the OpenGL VBO usage tip and shows a desire for interleaved arrays for static. A buffer object is not created if none is supplied, and vertex data is saved in system memory.
Examples:
v3f/stream : 3D vertex position using floats, for stream usage
c4b/static : 4-byte color attribute, for static usage
Returns: attribute, usage
create_domain(*attribute_usage_formats)
It is used to create a vertex domain that encompasses the attribute usage formats provided. The grammar of these format strings can be found in the documentation for creating attribute)_usage() and pyglet.graphics.vertexattribute.create_attribute().
Return type: VertexDomain
create_indexed_domain(*attribute_usage_formats)
It is used to create an indexed vertex domain that encompasses the attribute usage formats provided. The grammar of these format strings can be found in the documentation for creating attribute usage and pyglet.graphics.vertexattribute.create_attribute().
Return type: VertexDomain