Table of contents
1.
Introduction
2.
pyglet.graphics.vertexdomain
2.1.
classIndexedVertexDomain(attribute_usages, index_gl_type=5125)
2.1.1.
create(count, index_count)
2.1.2.
draw(mode, vertex_list=None)
2.1.3.
get_index_region(start, count)
2.2.
classIndexedVertexList(domain, start, count, index_start, index_count)
2.2.1.
delete()
2.2.2.
draw(mode)
2.2.3.
migrate(domain)
2.2.4.
resize(count, index_count)
2.2.5.
indices
2.3.
classVertexDomain(attribute_usages)
2.3.1.
create(count)
2.3.2.
draw(mode, vertex_list=None)
2.4.
classVertexList(domain, start, count)
2.4.1.
delete()
2.4.2.
draw(mode)
2.4.3.
get_domain()
2.4.4.
get_size()
2.4.5.
migrate(domain)
2.4.6.
resize(count)
2.4.7.
colors
2.4.8.
edge_flags
2.4.9.
fog_coords
2.4.10.
multi_tex_coords
2.4.11.
normals
2.4.12.
secondary_colors
2.4.13.
tex_coords
2.4.14.
vertices
2.5.
create_attribute_usage(fmt)
2.6.
create_domain(*attribute_usage_formats)
2.7.
create_indexed_domain(*attribute_usage_formats)
3.
Frequently Asked Questions
3.1.
What is a pyglet?
3.2.
What is a vertex domain?
3.3.
What is the use of the VertexDomain.draw() method?
4.
Conclusion
Last Updated: Mar 27, 2024

pyglet.graphics.vertexdomain

Author Nagendra
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

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') )?
You can also try this code with Online Python Compiler
Run Code

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

Frequently Asked Questions

What is a pyglet?

Pyglet is a Python library that provides an object-oriented application programming interface for the development of games and other multimedia applications.

What is a vertex domain?

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. 

What is the use of the VertexDomain.draw() method?

The VertexDomain.draw() method can efficiently draw the entire domain in one phase.

Conclusion

In this article, we have extensively discussed pyglet.graphics.vertexdomain. The article explains the details of pyglet.graphics.vertexdomain, and details of its different classes and predefined functions.
We hope that this blog has helped you enhance your knowledge regarding pyglet.graphics.vertexdomain, and if you would like to learn more, check out our articles on pyglet. You can refer to our guided paths on the Coding Ninjas Studio platform to learn more about DSADBMSCompetitive ProgrammingPythonJavaJavaScript, etc. To practice and improve yourself in the interview, you can also check out Top 100 SQL problemsInterview experienceCoding interview questions, and the Ultimate guide path for interviews.

Do upvote our blog to help other ninjas grow. 

Happy Coding!!

Live masterclass