Thanks andres. Good to see this problem will be fixed.
Unfortunately both your workarounds cause other issues themselves. noSmooth() solves the immediate issue, but this result is unusable because any subsequent call to beginDraw will clear it again. Using background(0, 0) does not allow accurate creation of pixels because of a mirror issue (already filed on googlecode). See below for details and examples.
noSmooth()
Using noSmooth will reset the PGraphics to fully transparent on each begin-endDraw call even when no background call is made. See the example code below. Without noSmooth() the drawing is cumulative (which is the expected behavior). With noSmooth() you only see one ellipse, because apparantly the PGraphics is cleared.
Background(0, 0)
Once background is used with full transparency on a PGraphics, mirror pixels will be created in the upper half of the PGraphics with the given greyscale color. I have already filed an issue for this here. Here is another example in which the top half is erroneously black.
Unfortunately both your workarounds cause other issues themselves. noSmooth() solves the immediate issue, but this result is unusable because any subsequent call to beginDraw will clear it again. Using background(0, 0) does not allow accurate creation of pixels because of a mirror issue (already filed on googlecode). See below for details and examples.
noSmooth()
Using noSmooth will reset the PGraphics to fully transparent on each begin-endDraw call even when no background call is made. See the example code below. Without noSmooth() the drawing is cumulative (which is the expected behavior). With noSmooth() you only see one ellipse, because apparantly the PGraphics is cleared.
- PGraphics pg;
- void setup() {
- size(500, 500, P2D);
- pg = createGraphics(width/2, height/2, P2D);
- pg.beginDraw();
- pg.noSmooth(); // comment out to see 'normal' cumulative drawing
- pg.endDraw();
- noFill();
- }
- void draw() {
- pg.beginDraw();
- pg.ellipse((float)mouseX/width*pg.width, (float)mouseY/height*pg.height, 50, 50);
- pg.endDraw();
- background(0, 255, 0);
- image(pg, width/4, height/4);
- rect(width/4, height/4, width/2, height/2);
- }
Background(0, 0)
Once background is used with full transparency on a PGraphics, mirror pixels will be created in the upper half of the PGraphics with the given greyscale color. I have already filed an issue for this here. Here is another example in which the top half is erroneously black.
- PGraphics pg;
- void setup() {
- size(500, 500, P2D);
- pg = createGraphics(width/2, height/2, P2D);
- noFill();
- }
- void draw() {
- setTransparent();
- background(0, 255, 0);
- image(pg, width/4, height/4);
- rect(width/4, height/4, width/2, height/2);
- }
- void setTransparent() {
- color transparent = color(0, 0);
- color red = color(255, 0, 0);
- pg.beginDraw();
- pg.background(0, 0);
- pg.loadPixels();
- for (int y=0; y<pg.height; y++) {
- for (int x=0; x<pg.width; x++) {
- if (y>pg.height/2) {
- pg.pixels[x+y*pg.width] = red;
- }
- }
- }
- pg.updatePixels();
- pg.endDraw();
- }