xxxxxxxxxx
34
let img;
let canvas;
let defShad;
function preload() {
img = loadImage('test.png');
}
function setup() {
canvas = createCanvas(400, 400, WEBGL);
noStroke();
defShad = createShader(vertShader, fragShader);
canvas.getTexture(img).setInterpolation(NEAREST, NEAREST);
}
function draw() {
background(0);
shader(defShad);
{
// The shaders didn't apply to what was drawn with image() and to a shape with a texture applied with texture()
image(img, -width / 2, -height / 2, width, height);
push();
{
texture(img);
rect(0, 0, 100, 100);
}
pop();
// The shaders only apply to this
rect(-100, -100, 100, 100);
}
resetShader();
}