Sets the texture that will be used on shapes.
A texture is like a skin that wraps around a shape. texture()
works with built-in shapes, such as square() and sphere(), and custom shapes created with functions such as buildGeometry(). To texture a geometry created with beginShape(), uv coordinates must be passed to each vertex() call.
The parameter, tex
, is the texture to apply. texture()
can use a range of sources including images, videos, and offscreen renderers such as p5.Graphics and p5.Framebuffer objects.
To texture a geometry created with beginShape(), you will need to specify uv coordinates in vertex().
Note: texture()
can only be used in WebGL mode.
Examples
Syntax
texture(tex)
Parameters
media to use as the texture.
Related References
copyToContext
Copies the shader from one drawing context to another.
inspectHooks
Logs the hooks available in this shader, and their current implementation.
modify
Returns a new shader, based on the original, but with custom snippets of shader code replacing default behaviour.
setUniform
Sets the shader’s uniform (global) variables.