Class pyglet.image.Texture

AbstractImage --+
                |
               Texture
Known Subclasses:
TextureRegion, DepthTexture, Texture3D, TileableTexture, font.base.GlyphTextureAtlas

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.

Methods

  __init__(self, width, height, target, id)
  delete(self)
Delete the texture from video memory.
  __del__(self)
Texture create(cls, width, height, internalformat=6408, rectangle=False)
Create an empty Texture.
Texture create_for_size(cls, target, min_width, min_height, internalformat=None)
Create a Texture with dimensions at least min_width, min_height.
ImageData get_image_data(self, z=0)
Get the image data of this texture.
Texture get_texture(self, rectangle=False)
A Texture view of this image.
  blit(self, x, y, z=0, width=None, height=None)
Draw this image to the active framebuffers.
  blit_into(self, source, x, y, z)
Draw source on this image.
AbstractImage get_region(self, x, y, width, height)
Retrieve a rectangular region of this image.
TextureRegion get_transform(self, flip_x=False, flip_y=False, rotate=0)
Create a copy of this image applying a simple transformation.
  __repr__(self) (Inherited from pyglet.image.AbstractImage)
  blit_to_texture(self, target, level, x, y, z=0)
Draw this image on the currently bound texture at target.
(Inherited from pyglet.image.AbstractImage)
Texture get_mipmapped_texture(self)
Retrieve a Texture instance with all mipmap levels filled in.
(Inherited from pyglet.image.AbstractImage)
  save(self, filename=None, file=None, encoder=None)
Save this image to a file.
(Inherited from pyglet.image.AbstractImage)

Properties

ImageData image_data
An ImageData view of this texture.
Texture mipmapped_texture
A Texture view of this image.
(Inherited from pyglet.image.AbstractImage)
Texture texture
Get a Texture view of this image.
(Inherited from pyglet.image.AbstractImage)

Instance Variables

tuple tex_coords = (0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0...
12-tuple of float, named (u1, v1, r1, u2, v2, r2, ...).
int level = 0
The mipmap level of this texture.
class (subclass of TextureRegion) region_class
Class to use when constructing regions of this texture.
int anchor_x = 0
X coordinate of anchor, relative to left edge of image data
(Inherited from pyglet.image.AbstractImage)
int anchor_y = 0
Y coordinate of anchor, relative to bottom edge of image data
(Inherited from pyglet.image.AbstractImage)
int height
Height of image
(Inherited from pyglet.image.AbstractImage)
int target
The GL texture target (e.g., GL_TEXTURE_2D).
int width
Width of image
(Inherited from pyglet.image.AbstractImage)

Class Variables

  tex_coords_order = (0, 1, 2, 3)
  images = 1
  z = 0
  y = 0
  x = 0

Method Details

__init__

(Constructor) __init__(self, width, height, target, id)
Overrides:
AbstractImage.__init__

delete

delete(self)
Delete the texture from video memory.

Deprecated: Textures are automatically released during object finalization.

create

Class Method create(cls, width, height, internalformat=6408, rectangle=False)

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

Since: pyglet 1.1

create_for_size

Class Method create_for_size(cls, target, min_width, min_height, internalformat=None)
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.
Returns: Texture

get_image_data

get_image_data(self, 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.
Returns: ImageData
Overrides:
AbstractImage.get_image_data

Since: pyglet 1.1

get_texture

get_texture(self, rectangle=False)

A Texture view of this image.

By default, textures are created with dimensions that are powers of two. Smaller images will return a TextureRegion that covers just the image portion of the larger texture. This restriction is required on older video cards, and for compressed textures, or where texture repeat modes will be used, or where mipmapping is desired.

If the rectangle parameter is True, this restriction is ignored and a texture the size of the image may be created if the driver supports the GL_ARB_texture_rectangle or GL_NV_texture_rectangle extensions. If the extensions are not present or the image already is a texture, the rectangle parameter is ignored.

Examine Texture.target to determine if the returned texture is a rectangle (GL_TEXTURE_RECTANGLE_ARB or GL_TEXTURE_RECTANGLE_NV) or not (GL_TEXTURE_2D).

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

Returns: Texture
Overrides:
AbstractImage.get_texture

Since: pyglet 1.1

blit

blit(self, x, y, z=0, width=None, height=None)

Draw this image to the active framebuffers.

The image will be drawn with the lower-left corner at (x - anchor_x, y - anchor_y, z).

Overrides:
AbstractImage.blit

blit_into

blit_into(self, source, x, y, z)

Draw source on this image.

source will be copied into this image such that its anchor point is aligned with the x and y parameters. If this image is a 3D texture, the z coordinate gives the image slice to copy into.

Note that if source is larger than this image (or the positioning would cause the copy to go out of bounds) then you must pass a region of source to this method, typically using get_region().

Overrides:
AbstractImage.blit_into

get_region

get_region(self, x, y, width, height)
Retrieve a rectangular region of this image.
Returns: AbstractImage
Overrides:
AbstractImage.get_region

get_transform

get_transform(self, 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.
Returns: TextureRegion

Property Details

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.

Deprecated: Use get_image_data.

Type:
ImageData

Instance Variable Details

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.
Type:
tuple
Value:
(0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0)

region_class

Class to use when constructing regions of this texture.
Type:
class (subclass of TextureRegion)
Value:
pyglet.image.TextureRegion