PGraphics pg;
void setup() {
size(800, 800, P2D);
pg = createGraphics(width, height, P2D);
pg.beginDraw();
pg.noStroke();
pg.clear();
pg.fill(255, 127);
pg.rect(0, 0, 195, height);
printColor(pg.get(10, 10));
pg.endDraw();
background(0);
image(pg, 0, 0);
}
void draw() {
pg.beginDraw();
//pg.clear();
pg.fill(255, 127);
switch(frameCount) {
case 1 :
pg.rect(200, 0, 195, height);
printColor(pg.get(210, 10));
break;
case 2 :
pg.rect(400, 0, 195, height);
printColor(pg.get(410, 10));
break;
case 3 :
pg.rect(600, 0, 195, height);
printColor(pg.get(610, 10));
break;
}
pg.endDraw();
background(0);
image(pg, 0, 0);
}
void printColor(int c) {
println("color RBGA: (" +
red(c) + ", " +
green(c) + ", " +
blue(c) + ", " +
alpha(c) + ")");
}
This is my attempt to figure out why my images are darker than they’re supposed to be sometimes, and I admit that I’m completely lost. It’s seriously messing up a project I’m trying to work on. Colors below are in RGBA format.
The 4 rectangles are supposed to be 255, 255, 255, 127
as I’ve set in the fill()
methods. In the above code, the colors of the four rectangles are apparently 127, 127, 127, 127
. If you comment out pg.clear();
in setup()
, then the color of the fist rectangle is 229, 229, 229, 127
for some reason. Uncommenting pg.clear();
in draw()
doesn’t seem to make a difference (besides making it so you can’t see anything which is expected). When I analyze the colors using an image editor, then they’re 63, 63, 63
when they should be 127, 127, 127
because it’s drawn onto the primary PGraphics
set to 0, 0, 0, 255
. In any case, I can’t get the first rectangle to even show up on screen.
Furthermore, If I change just the primary to the default renderer, it crashes. (I think this is supposed to be unsurprising, but makes the next result confusing.) If I instead change just pg
to the default renderer or I change both to the default renderer, then all the colors in all situations described above are correct. The first rectangle even shows up. Unfortunately I kind of need P2D
because it’s way faster, and I’m doing something that requires a lot of computation.
I can’t make sense of any of this. All I want to do is draw a translucent shape onto a transparent PGraphics
then draw that onto the primary without having all of these strange color anomalies.
I originally posted on the GitHub, but they directed me here. Am I just doing it wrong, or is this truly a bug?