Py5Shape.texture_mode()#

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

Examples#

example picture for texture_mode()
 1def setup():
 2    py5.size(100, 100, py5.P3D)
 3    py5.no_stroke()
 4    img = py5.load_image("laDefense.jpg")
 5    # call py5.texture_mode() here to inherit mode setting
 6    # py5.texture_mode(py5.IMAGE)
 7    s = py5.create_shape()
 8    s.begin_shape()
 9    s.texture(img)
10    s.texture_mode(py5.IMAGE)
11    s.vertex(10, 20, 0, 0)
12    s.vertex(80, 5, 100, 0)
13    s.vertex(95, 90, 100, 100)
14    s.vertex(40, 95, 0, 100)
15    s.end_shape()
16
17    py5.shape(s)
example picture for texture_mode()
 1def setup():
 2    py5.size(100, 100, py5.P3D)
 3    py5.no_stroke()
 4    img = py5.load_image("laDefense.jpg")
 5    # call py5.texture_mode() here to inherit mode setting
 6    # py5.texture_mode(py5.NORMAL)
 7    s = py5.create_shape()
 8    s.begin_shape()
 9    s.texture(img)
10    s.texture_mode(py5.NORMAL)
11    s.vertex(10, 20, 0, 0)
12    s.vertex(80, 5, 1, 0)
13    s.vertex(95, 90, 1, 1)
14    s.vertex(40, 95, 0, 1)
15    s.end_shape()
16
17    py5.shape(s)

Description#

Sets a Py5Shape object’s coordinate space for texture mapping. 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.

If this method is not used, it will inherit the current texture mode setting from the Sketch when the shape is created.

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

Syntax#

texture_mode(mode: int, /) -> None

Parameters#

  • mode: int - either IMAGE or NORMAL

Updated on November 12, 2021 11:30:58am UTC