Layer alpha-blending with PGraphics
in
Programming Questions
•
2 years ago
Hi, I'm doing simple painting tool, where I wan't alpha-blend several layers. It's working quite well using GLGraphics, however because of compactibility with older computers (or not instaled drivers like on Linux) I wan't also to do it with standard Processing PGraphics.
However, the result is not what I want. Instead of blending new layer with background pixel color, the image()
blend layer with black (Completly opaque)
See folowing simple example
However, the result is not what I want. Instead of blending new layer with background pixel color, the image()
blend layer with black (Completly opaque)
See folowing simple example
- int sx=500; int sy=500;
PGraphics GUI, Canvas;
PGraphics Layer1;
PGraphics Layer2;
void setup() {
size(sx, sx,P2D);
//smooth();
GUI = createGraphics(sx, sx,P2D);
Layer1 = createGraphics(sx, sx,P2D);
Layer2 = createGraphics(sx, sx,P2D);
frameRate(60);
Layer1.beginDraw();
GUI.background(255,0);
Layer1.fill(255,0,0,50); Layer1.noStroke();
Layer1.beginDraw();
Layer2.beginDraw();
GUI.background(0,0);
Layer2.fill(0,0,255,50); Layer2.noStroke();
Layer2.beginDraw();
}
void draw() {
GUI.beginDraw();
GUI.background(255,0);
GUI.noFill();
GUI.ellipse(mouseX, mouseY,20,20);
GUI.endDraw();
if (mousePressed == true){
if(mouseButton == LEFT){Canvas = Layer1; }else{Canvas = Layer2;};
Canvas.beginDraw();
Canvas.ellipse(mouseX, mouseY,20,20);
Canvas.endDraw();
{
}
}
background(200);
image(Layer1, 0, 0);
image(Layer2, 0, 0);
image(GUI, 0, 0);
}
1