xxxxxxxxxx
43
let fbo;
let mode = "c";
function setup() {
createCanvas(400, 400, WEBGL);
fbo = createFramebuffer();
noStroke();
}
function draw() {
// Draw a box to the Framebuffer
fbo.draw(() => {
clear()
push()
noStroke()
fill(255, 0, 0)
rotateX(frameCount * 0.01)
rotateY(frameCount * 0.01)
box(50)
fill(0, 0, 255);
translate(0, 0, 150);
sphere(10);
pop()
});
let img;
if(mode === "c") {
img = fbo.color;
} else if(mode === "d") {
img = fbo.depth;
}
image(img, -width/2, -height/2, width, height);
}
function keyReleased() {
if(key === "c" || key === "d") {
mode = key;
}
}