I’m trying to use get() to make patterns using the previous frame, so I’m calling get() at the start of draw().
If I use background() after that to clear the frame, I find that what get() has given me is not the previous frame but the frame before that.
I’ve made a simple 2D sketch that shows the issue. It draws alternating green and blue circles along the bottom of the window. When I use background() I see alternating frames of all green or all blue circles:
!
However, if I remove background() and just draw a rect() the same size as the screen, which I would think should be equivalent to using background() in this sketch, I find that get() has given me the previous frame as intended and I get a mixture of green and blue circles.
The grey circles I tried adding before get() to see what would happen. They appear in the right place, but if background() is used they’re drawn on top of the wrong frame.
What’s going on here?
Here’s my code
PImage getWindow;
void setup() {
size(400, 300, P3D);
frameRate(2);
}
void draw() {
fill(150);
ellipse( 40 + (width / 5) * (frameCount % 5), 270, 50, 50);
getWindow = get();
//remove this to see the difference
background(128);
fill(128);
rect(0, 0, width, height);
fill( 0, 255 * ((frameCount + 1) % 2), 255 * (frameCount % 2));
ellipse( 40 + (width / 5) * (frameCount % 5), 270, 50, 50);
beginShape();
texture(getWindow);
vertex( 50, 10, 0, 0, 0);
vertex( 350, 10, 0, width, 0);
vertex( 350, 235, 0, width, height);
vertex( 50, 235, 0, 0, height);
endShape(CLOSE);
}