Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translucent shapes appear darker than they should using P2D in setup() after clear() #627

Closed
processing-bot opened this issue Dec 21, 2022 · 4 comments

Comments

@processing-bot
Copy link
Collaborator

Created by: PianoMastR64

void setup() {
  size(800, 800, P2D);
  
  noLoop();
  clear();
  noStroke();
  //stroke(255, 0, 0, 255/2);
  //strokeWeight(50);
  fill(255, 255/2);
  
  square(0, 0, 400);    // top left
  printColor(get(200, 200));    // prints top left color info
}

void draw() {
  square(400, 400, 400);    // bottom right
  printColor(get(200, 200));    // prints top left color info
  printColor(get(600, 600));    // prints bottom right color info
}

void printColor(color c){
  println("color: (" + 
    red(c) + ", " + 
    green(c) + ", " + 
    blue(c) + ", " + 
    alpha(c) + ")");
}

If you run this code, you'll see that even though the fill color is the same for both squares, the first one in setup() appears darker than it should. The other square in draw() is drawn correctly. This is only a problem when using the P2D renderer after calling clear(), which effectively calls background(0, 0).

If you modify only the renderer to the default size(800, 800);, then both squares are drawn correctly. If you modify only the clear() line into background(0), then both squares are also drawn correctly.

I commented out the stroke lines because they're a bit distracting, but they also convey some interesting information as they're also affected by this bug.

It's also interesting to note that get() in setup() insists that the top left square is (127, 127, 127, 127), but in draw() it says it's (63, 63, 63, 127) which is what Paint confirms it is in a screenshot (minus the alpha).

One more thing is that only translucent shapes are affected, and the lower the alpha, the more dramatic the effect.

@processing-bot
Copy link
Collaborator Author

Created by: PianoMastR64

I'm trying to do tests to figure out the problem, but it just keeps getting more confusing.

void setup() {
  size(800, 800, P2D);

  //noLoop();
  clear();
  noStroke();
  fill(255, 255/2);

  rect(0, 0, 195, height);    // rect 1
}

void draw() {

  switch(frameCount) {
  case 1:
    rect(200, 0, 195, height);    // rect 2
    break;
  case 2:
    rect(400, 0, 195, height);    // rect 3
    break;
  case 3:
    rect(600, 0, 195, height);    // rect 4
    break;
  }
}

Apparently noLoop() affects this bug in an unexpected way. If noLoop() is on, then the fist rect is dark and the second is correct. The rest don't draw for obvious reasons. But if noLoop() is off, the first two are dark, and the next two (and I assume the rest from that point forward) are correct.

@processing-bot
Copy link
Collaborator Author

Created by: benfry

clear() should only be used with surfaces from createGraphics(), not the main drawing surface. (And you're finding out why…)

This is covered on the reference page: https://processing.org/reference/clear_.html

@processing-bot
Copy link
Collaborator Author

Created by: benfry

Added a warning for 4.1.2; thought we had one already, but nope.

@processing-bot
Copy link
Collaborator Author

Created by: github-actions[bot]

This issue has been automatically locked. To avoid confusion with reports that have already been resolved, closed issues are automatically locked 30 days after the last comment. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant