Texture Class

Inheritance diagram of Texture

class Texture(width, height, target, id)

An image loaded into video memory that can be efficiently drawn to the framebuffer.

Typically you will get an instance of Texture by accessing the texture member of any other AbstractImage.

Variables:
  • region_class – Class to use when constructing regions of this texture.
  • tex_coords – 12-tuple of float, named (u1, v1, r1, u2, v2, r2, ...). u, v, r give the 3D texture coordinates for vertices 1-4. The vertices are specified in the order bottom-left, bottom-right, top-right and top-left.
  • target – The GL texture target (e.g., GL_TEXTURE_2D).
  • level – The mipmap level of this texture.

Constructor:

__init__(width, height, target, id)

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([z]) Get the image data of this texture.
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

Texture.blit(x, y, z=0, width=None, height=None)
Texture.blit_into(source, x, y, z)
classmethod Texture.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 Texture.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

Texture.delete()

Delete the texture from video memory.

Warning

Deprecated. Textures are automatically released during object finalization.

Texture.get_image_data(z=0)

Get the image data of this texture.

Changes to the returned instance will not be reflected in this texture.

Parameters:z (int) – For 3D textures, the image slice to retrieve.
Return type:ImageData
Texture.get_region(x, y, width, height)
Texture.get_texture(rectangle=False, force_rectangle=False)
Texture.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

Attributes

Texture.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
Texture.images = 1
Texture.level = 0
Texture.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)
Texture.tex_coords_order = (0, 1, 2, 3)
Texture.x = 0
Texture.y = 0
Texture.z = 0

Inherited members

Methods

Texture.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.

Texture.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

Texture.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

Texture.anchor_x = 0
Texture.anchor_y = 0
Texture.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
Texture.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

Table Of Contents

Previous topic

SolidColorImagePattern Class

Next topic

Texture3D Class