Basically, I don't know why the get() doesn't work...
But well, I could make your code to work.
Notes:
- For pg to work as a transparent overlay, you must not put a background() call in it.
- You must wrap the pg.xxx() calls with beginDraw/endDraw.
- I used a PGraphics instead of a PImage for frame, so I can use image() instead of get().
Code:PGraphics pg;
PGraphics frame;
boolean displayOverlay = true;
boolean displayFrame;
void setup() {
size(600, 600, JAVA2D);
background(230);
fill(255, 0, 0);
stroke(0);
strokeWeight(6);
pg = createGraphics(width, height, JAVA2D);
pg.beginDraw();
pg.noFill();
pg.stroke(0);
pg.strokeWeight(6);
pg.endDraw();
frame = createGraphics(width, height, JAVA2D);
}
void draw() {
background(230);
rect(250, 250, 100, 100);
if (mousePressed && displayOverlay) {
pg.beginDraw();
pg.line(mouseX, mouseY, pmouseX, pmouseY);
pg.endDraw();
}
if (displayOverlay)
image(pg, 0, 0);
if (displayFrame)
image(frame, 0, 0);
}
void keyPressed() {
if (key == 'd') {
displayOverlay = !displayOverlay;
println("Toggling overlay.");
}
if (key == 's') {
frame.beginDraw();
frame.image(pg, 0, 0);
frame.endDraw();
println("Saving overlay.");
}
if (key == 'a') {
displayFrame = !displayFrame;
println("Toggling frame.");
}
}