Texture2D¶
Create¶
-
classmethod
Texture2D.
create
(size, components=4, data=None, samples=0, alignment=1, dtype='f1', mipmap=False) → Texture2D¶ Creates a 2d texture. All parameters are passed on the texture initializer.
Parameters: - size – (tuple) Width and height of the texture
- components – Number of components
- data – Buffer data for the texture
- samples – Number of samples when using multisaple texture
- alignment – Data alignment (1, 2, 4 or 8)
- dtype – Datatype for each component
- mipmap – Generate mipmaps
Returns: Texture object
-
classmethod
Texture2D.
from_image
(path, image=None, **kwargs)¶ Creates a texture from a image file using Pillow/PIL. Additional parameters is passed to the texture initializer.
Parameters: - path – The path to the file
- image – The PIL/Pillow image object (Can be None)
Returns: Texture object
Methods¶
-
Texture2D.
use
(location=0)¶ Bind the texture.
Parameters: location – The texture location. (GL_TEXTURE0 + location)
-
Texture2D.
build_mipmaps
(base=0, max_level=1000)¶ Build mipmaps for this texture
Parameters: - base – Level to build from
- max_level – Max levels
-
Texture2D.
set_image
(image, flip=True)¶ Set pixel data using a image file with PIL/Pillow.
Parameters: - image – The PIL/Pillow image object
- flip – Flip the image top to bottom
-
Texture2D.
draw
(pos=(0.0, 0.0), scale=(1.0, 1.0))¶ Draw texture
Parameters: - pos – (tuple) offset x, y
- scale – (tuple) scale x, y
-
Texture2D.
read
(level:int=0, alignment:int=1) → bytes¶ Read the content of the texture into a buffer.
Parameters: - level – The mipmap level.
- alignment – The byte alignment of the pixels.
Returns: bytes
-
Texture2D.
read_into
(buffer:bytearray, level:int=0, alignment:int=1, write_offset:int=0)¶ Read the content of the texture into a buffer.
Parameters: - buffer – (bytearray) The buffer that will receive the pixels.
- level – (int) The mipmap level.
- alignment – (int) The byte alignment of the pixels.
- write_offset – (int) The write offset.
-
Texture2D.
write
(data:bytes, viewport=None, level:int=0, alignment:int=1)¶ Update the content of the texture.
Parameters: - data – (bytes) – The pixel data.
- viewport – (tuple) – The viewport.
- level – (int) – The mipmap level.
- alignment – (int) – The byte alignment of the pixels.
Attributes¶
-
Texture2D.
size
¶ The size of the texture
-
Texture2D.
width
¶ Width of the texture
-
Texture2D.
height
¶ Height of the texture
-
Texture2D.
dtype
¶ The data type of the texture
-
Texture2D.
depth
¶ Is this a depth texture?
-
Texture2D.
swizzle
¶
-
Texture2D.
size
The size of the texture
-
Texture2D.
ctx
¶ ModernGL context