TextureRegion Class

Inheritance diagram of TextureRegion

class TextureRegion(x, y, z, width, height, owner)

A rectangular region of a texture, presented as if it were a separate texture.

Constructor:

__init__(x, y, z, width, height, owner)

Methods:

blit(x, y[, z, width, height])
blit_into(source, x, y, z)
blit_to_texture(target, level, x, y[, z]) Draw this image on the currently bound texture at target.
create(width, height[, internalformat, ...]) Create an empty Texture.
create_for_size(target, min_width, min_height) Create a Texture with dimensions at least min_width, min_height.
delete() Delete the texture from video memory.
get_image_data()
get_mipmapped_texture() Retrieve a Texture instance with all mipmap levels filled in.
get_region(x, y, width, height)
get_texture([rectangle, force_rectangle])
get_transform([flip_x, flip_y, rotate]) Create a copy of this image applying a simple transformation.
save([filename, file, encoder]) Save this image to a file.

Attributes:

anchor_x Type: int
anchor_y Type: int
image_data An ImageData view of this texture.
images Type: int
level Type: int
mipmapped_texture A Texture view of this image.
tex_coords Type: tuple
tex_coords_order Type: tuple
texture Get a Texture view of this image.
x Type: int
y Type: int
z Type: int

Methods

TextureRegion.blit_into(source, x, y, z)
TextureRegion.get_image_data()
TextureRegion.get_region(x, y, width, height)

Inherited members

Methods

TextureRegion.blit(x, y, z=0, width=None, height=None)
TextureRegion.blit_to_texture(target, level, x, y, z=0)

Draw this image on the currently bound texture at target.

This image is copied into the texture such that this image’s anchor point is aligned with the given x and y coordinates of the destination texture. If the currently bound texture is a 3D texture, the z coordinate gives the image slice to blit into.

classmethod TextureRegion.create(width, height, internalformat=6408, rectangle=False, force_rectangle=False, min_filter=9729, mag_filter=9729)

Create an empty Texture.

If rectangle is False or the appropriate driver extensions are not available, a larger texture than requested will be created, and a TextureRegion corresponding to the requested size will be returned.

Parameters:
  • width (int) – Width of the texture.
  • height (int) – Height of the texture.
  • internalformat (int) – GL constant giving the internal format of the texture; for example, GL_RGBA.
  • rectangle (bool) – True if a rectangular texture is permitted. See AbstractImage.get_texture.
  • force_rectangle (bool) – True if a rectangular texture is required. See AbstractImage.get_texture. Since: pyglet 1.1.4.
  • min_filter (int) – The minifaction filter used for this texture, commonly GL_LINEAR or GL_NEAREST
  • mag_filter (int) – The magnification filter used for this texture, commonly GL_LINEAR or GL_NEAREST
Return type:

Texture

Note

Since pyglet 1.1

classmethod TextureRegion.create_for_size(target, min_width, min_height, internalformat=None, min_filter=9729, mag_filter=9729)

Create a Texture with dimensions at least min_width, min_height. On return, the texture will be bound.

Parameters:
  • target (int) – GL constant giving texture target to use, typically GL_TEXTURE_2D.
  • min_width (int) – Minimum width of texture (may be increased to create a power of 2).
  • min_height (int) – Minimum height of texture (may be increased to create a power of 2).
  • internalformat (int) – GL constant giving internal format of texture; for example, GL_RGBA. If unspecified, the texture will not be initialised (only the texture name will be created on the instance). If specified, the image will be initialised to this format with zero’d data.
  • min_filter (int) – The minifaction filter used for this texture, commonly GL_LINEAR or GL_NEAREST
  • mag_filter (int) – The magnification filter used for this texture, commonly GL_LINEAR or GL_NEAREST
Return type:

Texture

TextureRegion.delete()

Delete the texture from video memory.

Warning

Deprecated. Textures are automatically released during object finalization.

TextureRegion.get_mipmapped_texture()

Retrieve a Texture instance with all mipmap levels filled in.

Requires that image dimensions be powers of 2.

Return type:Texture

Note

Since pyglet 1.1

TextureRegion.get_texture(rectangle=False, force_rectangle=False)
TextureRegion.get_transform(flip_x=False, flip_y=False, rotate=0)

Create a copy of this image applying a simple transformation.

The transformation is applied to the texture coordinates only; get_image_data will return the untransformed data. The transformation is applied around the anchor point.

Parameters:
  • flip_x (bool) – If True, the returned image will be flipped horizontally.
  • flip_y (bool) – If True, the returned image will be flipped vertically.
  • rotate (int) – Degrees of clockwise rotation of the returned image. Only 90-degree increments are supported.
Return type:

TextureRegion

TextureRegion.save(filename=None, file=None, encoder=None)

Save this image to a file.

Parameters:
  • filename (str) – Used to set the image file format, and to open the output file if file is unspecified.
  • file (file-like object or None) – File to write image data to.
  • encoder (ImageEncoder or None) – If unspecified, all encoders matching the filename extension are tried. If all fail, the exception from the first one attempted is raised.

Attributes

TextureRegion.anchor_x = 0
TextureRegion.anchor_y = 0
TextureRegion.image_data

An ImageData view of this texture.

Changes to the returned instance will not be reflected in this texture. If the texture is a 3D texture, the first image will be returned. See also get_image_data. Read-only.

Warning

Deprecated. Use get_image_data.

Type:ImageData
TextureRegion.images = 1
TextureRegion.level = 0
TextureRegion.mipmapped_texture

A Texture view of this image.

The returned Texture will have mipmaps filled in for all levels. Requires that image dimensions be powers of 2. Read-only.

Warning

Deprecated. Use get_mipmapped_texture.

Type:Texture
TextureRegion.tex_coords = (0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0)
TextureRegion.tex_coords_order = (0, 1, 2, 3)
TextureRegion.texture

Get a Texture view of this image.

Changes to the returned instance may or may not be reflected in this image.

Warning

Deprecated. Use get_texture.

Type:Texture
TextureRegion.x = 0
TextureRegion.y = 0
TextureRegion.z = 0

Table Of Contents

Previous topic

TextureGrid Class

Next topic

TextureSequence Class