Using P2D, I can use image() to copy an image from one PGraphics to another many times. With the default renderer, I can copy only once. Is this a known behavior? Is this logical behavior?
When running this sketch, press 1 thru 4. 2 looks like 1, 4 is supposed to look like 3 but doesn't unless P2D is added. The second pg2.image() does not work.
This was a bit confusing for me because you are layering content into buffers and then referencing them for your cases -- so the whole thing is full of side-effects that are dependent on pushing keys in a specific order and then stopping.
Here is a working example based on yours (only with the interactivity and variable reuse removed). It uses only PGraphics.image() to copy from one PGraphics to another with correct results -- without using the P2D renderer.
I haven't dug deeper to see what the actual problem is with your MCVE, but PGraphics.image(PGraphics) does work in the default renderer, as you can see.
My problem with PGraphics.image(PGraphics) in the default renderer is that it only works the first time. In my MCVE (when pressing 1 thru 4 in order), image() works the first time but not the second.
I am currently able to work around this by using P2D.
And after that, try adding this to setup below everything else. We'll use two different PGraphics AND draw each one twice multiple times AND do it all in the same beginDraw/endDraw -- that's four different PGraphics.image(PGraphics) calls:
My best next guesses would be that you have confused your fill() commands with background() commands, and so you expect your original sketch to be doing something (clearing then replacing) that it doesn't actually to -- and/or that you aren't clear on the PGraphics having a transparent background by default, so you are surprised when the single rectangle drawn on top of two rectangles looks like two rectangles.
Answers
Can you please post a MCVE that demonstrates the behavior?
When running this sketch, press 1 thru 4. 2 looks like 1, 4 is supposed to look like 3 but doesn't unless P2D is added. The second pg2.image() does not work.
Thank you for making an MCVE.
This was a bit confusing for me because you are layering content into buffers and then referencing them for your cases -- so the whole thing is full of side-effects that are dependent on pushing keys in a specific order and then stopping.
Here is a working example based on yours (only with the interactivity and variable reuse removed). It uses only
PGraphics.image()
to copy from one PGraphics to another with correct results -- without using the P2D renderer.I haven't dug deeper to see what the actual problem is with your MCVE, but PGraphics.image(PGraphics) does work in the default renderer, as you can see.
My problem with PGraphics.image(PGraphics) in the default renderer is that it only works the first time. In my MCVE (when pressing 1 thru 4 in order), image() works the first time but not the second.
I am currently able to work around this by using P2D.
Re:
I'm just not seeing that. Try adding this to the end of setup:
Okay, now pg2r is blank.
Now add this below it in setup:
Okay, we drew a PGraphics using image -- twice -- and it worked fine.
And after that, try adding this to setup below everything else. We'll use two different PGraphics AND draw each one twice multiple times AND do it all in the same beginDraw/endDraw -- that's four different PGraphics.image(PGraphics) calls:
...works just fine.
My best next guesses would be that you have confused your
fill()
commands withbackground()
commands, and so you expect your original sketch to be doing something (clearing then replacing) that it doesn't actually to -- and/or that you aren't clear on the PGraphics having a transparent background by default, so you are surprised when the single rectangle drawn on top of two rectangles looks like two rectangles.