Texture management

OpenGL texture can be a pain to manage ourself, except if you know perfectly all the OpenGL API :).

class kivy.graphics.texture.Texture(width, height, target, texid, fmt='rgb', mipmap=False, rectangle=False)

Bases: object

Handle a OpenGL texture. This class can be used to create simple texture or complex texture based on ImageData.

bind()

Bind the texture to current opengl state

blit_buffer(pbuffer, size=None, fmt=None, pos=None, buffertype=None)

Blit a buffer into a texture.

Parameters:
pbuffer : str

Image data

size : tuple, default to texture size

Size of the image (width, height)

fmt : str, default to ‘rgb’

Image format, can be one of ‘rgb’, ‘rgba’, ‘bgr’, ‘bgra’

pos : tuple, default to (0, 0)

Position to blit in the texture

buffertype : str, default to ‘ubyte’

Type of the data buffer, can be one of ‘ubyte’, ‘ushort’, ‘uint’, ‘byte’, ‘short’, ‘int’, ‘float’

blit_data(im, pos=None)

Replace a whole texture with a image data

create()

texture_create(size=None, fmt=None, buffertype=None, rectangle=False, mipmap=False) Create a texture based on size.

Parameters:
size: tuple, default to (128, 128)

Size of the texture

fmt: str, default to ‘rgba’

Internal format of the texture. Can be ‘rgba’ or ‘rgb’

rectangle: bool, default to False

If True, it will use special opengl command for creating a rectangle texture. It’s not available on OpenGL ES, but can be used for desktop. If we are on OpenGL ES platform, this parameter will be ignored.

mipmap: bool, default to False

If True, it will automatically generate mipmap texture.

create_from_data()

texture_create_from_data(im, rectangle=True, mipmap=False) Create a texture from an ImageData class

disable()

Do the appropriate glDisable()

enable()

Do the appropriate glEnable()

flip_vertical()

Flip tex_coords for vertical displaying

get_region(x, y, width, height)
Return a part of the texture, from (x,y) with (width,height)
dimensions
height(readonly)
id(readonly)
mag_filter

Get/set the GL_TEXTURE_MAG_FILTER property

min_filter

Get/set the GL_TEXTURE_MIN_FILTER property

mipmap(readonly)
rectangle(readonly)
target(readonly)
tex_coords(opengl)
uvpos

Get/set the UV position inside texture

uvsize

Get/set the UV size inside texture.

Warning

The size can be negative is the texture is flipped.

width(readonly)
wrap

Get/set the GL_TEXTURE_WRAP_S,T property

class kivy.graphics.texture.TextureRegion(int x, int y, int width, int height, Texture origin)

Bases: kivy.graphics.texture.Texture

Handle a region of a Texture class. Useful for non power-of-2 texture handling.