please format code with </> button * homework policy * asking questions
I know this question has been asked in one form of another, but I wanted to pose it here in terms of getting the default blend drawing mode to work similarly between JAVA2D and P2D. Underneath the hood, I believe the problem is with the implementation of the source-over-alpha blending mode, which is working correctly in JAVA2D, but not in P2D (or P3D for that matter)
In the code below, we only get correct behavior when using JAVA2D. When using P2D, the resulting drawing has premultiplication issues which cause a blackish kind of ghosting to build over time.
Is there a way to get the P2D mode to properly composite this sketch? Note the results can be seen both onscreen, and in the test.png that the sketch saves when releasing the mouse.
Any pointers would be much appreciated.
String RENDERER = P2D; // JAVA2D; // or P2D
int BLND = BLEND; // one of BLEND ADD SUBTRACT DARKEST LIGHTEST DIFFERENCE EXCLUSION MULTIPLY SCREEN REPLACE
color rgb_gry = color(60); //grey
color rgb_circle = color(220,220,100,5); // yellowish
String file_out = "test.png";
PGraphics layer;
public void settings() {
size(640, 480, RENDERER);
} // end of settings
void setup(){
layer = createGraphics(width, height, RENDERER);
layer.beginDraw();
layer.blendMode(BLND);
layer.ellipseMode(CENTER);
layer.noStroke();
layer.strokeJoin(ROUND);
layer.endDraw();
}
void draw() {
background(rgb_gry); // set bg color to grey
image(layer, 0, 0);
} // end of draw()
void mouseDragged() {
layer.beginDraw();
layer.fill(rgb_circle);
layer.ellipse(mouseX, mouseY, 100, 100);
layer.endDraw();
} // end of void mouseDragged()
void mouseReleased() {
layer.save(file_out);
println ("...Wrote out file " + file_out);
} // end of void mouseReleased()