Py5Shape.set_texture_mode()

Py5Shape.set_texture_mode()#

Sets a Py5Shape object’s coordinate space for texture mapping.

Examples#

example picture for set_texture_mode()

def setup():
    py5.size(100, 100, py5.P2D)
    img = py5.load_image("tower.jpg")
    s = py5.create_shape()
    s.begin_shape()
    s.vertex(20, 20)
    s.vertex(20, 80)
    s.vertex(80, 80)
    s.vertex(80, 20)
    s.end_shape(py5.CLOSE)

    s.set_texture(img)
    s.set_texture_mode(py5.NORMAL)
    s.set_texture_uv(0, 0, 0)
    s.set_texture_uv(1, 0, 1)
    s.set_texture_uv(2, 1, 1)
    s.set_texture_uv(3, 1, 0)

    py5.shape(s)

Description#

Sets a Py5Shape object’s coordinate space for texture mapping. This method differs from Py5Shape.texture_mode() in that it is only to be used outside the Py5Shape.begin_shape() and Py5Shape.end_shape() methods. Use of this method should be followed by calls to Py5Shape.set_texture_uv() to set the mapping coordinates using the new mode.

The default mode is IMAGE, which refers to the actual pixel coordinates of the image. NORMAL refers to a normalized space of values ranging from 0 to 1. This function only works with the P2D and P3D renderers.

With IMAGE, if an image is 100 x 200 pixels, mapping the image onto the entire size of a quad would require the points (0,0) (100,0) (100,200) (0,200). The same mapping in NORMAL is (0,0) (1,0) (1,1) (0,1).

Underlying Processing method: PShape.setTextureMode

Signatures#

set_texture_mode(
    mode: int,  # either IMAGE or NORMAL
    /,
) -> None

Updated on March 06, 2023 02:49:26am UTC