Weird error with P3D

edited March 2017 in GLSL / Shaders

Okay, this was not happening a while ago and I have NO IDEA why this stop working.

It only happens with P3D.

after a background() function happens that the shape that I working always draw in the back and not in the front as it was being draw at first. The weird thing is that is only the body NOT THE STROKE of the shape.

This is my code.

boolean isbg = false;
void setup(){

  size(1200,600,P3D);
     background(0); 
}

void draw(){

  if (isbg){
   background(0); 
  }
 ellipse(mouseX,mouseY,100,100);

}

void keyPressed(){

  if (key == 'd'){
  isbg = !isbg; 
 }
}

This happen EVERYTIME after a background() function runs.

this just destroyed an entire soft that I was working with.
Happens even if is an ellipse, a rect or a personal shape.

I ´VE TRYED EVERYTHING

It is always AFTER the background function runs.

Answers

  • after pressing 'd' the background changes EVERY frame, until you press 'd' again.

    add line 14

    isbg = false;
    

    (assuming that's what you want)

  • edited December 2016

    shape that I working always draw in the back and not in the front

    I see what you mean. After turning the background off and on, something very strange happens to the way the fill and stroke are applied to the canvas. White pixels fill no longer overwrite old lines.

    This change to your test sketch uses frameRate() to make it easier to see what is happening:

    // Processing P3D background on/off bug?
    // press d - d to turn background off, then on again to reveal bug.
    // PDE 3.2.3 -- OS X 10.10.5
    boolean isbg = false;
    void setup() {
      size(200, 200, P3D);
      frameRate(6);
      background(0);
    }
    void draw() {
      if (isbg) background(0);
      ellipse(mouseX, mouseY, 40, 40);
    }
    void keyPressed() {
      if (key == 'd') isbg = !isbg;
    }
    

    BugP3DBackground BugP3DBackground2

    This looks like it might be a bug. I would suggest reporting it to Processing Issues: https://github.com/processing/processing/issues

  • not seeing that here in 3.0 or in 3.1.1 (linux)

  • edited March 2017

    Well i don´t know if actually solved the problem

    Turns out I was not really needing

    P3D

    So i´ve change it to P2D and it works just fine

  • edited March 2017 Answer ✓

    This is an optimisation applied to the stroke when working in 3D. When the optimised stroke is enabled ALL the strokes are drawn after ALL the fills.

    When disabled the they are drawn in depth order.

    boolean isbg = false;
    
    void setup() {
      size(1200, 600, P3D);
      background(0); 
      hint(DISABLE_OPTIMIZED_STROKE);
    }
    
    void draw() {
      if (isbg) {
        background(0);
      }
      ellipse(mouseX, mouseY, 100, 100);
    }
    
    void keyPressed() {
      if (key == 'd') {
        isbg = !isbg;
      }
    }
    

    In P2D they are drawn in the order drawn because all 2D shapes are at the same depth i.e. z=0

  • edited March 2017

    Thank you, @quark. Very clear explanation.

    For those unfamiliar with hint(), I believe that:

    1. It is not documented in the reference
    2. It is not documented in the JavaDoc http://processing.github.io/processing-javadocs/core/processing/core/PApplet.html#hint-int-
    3. You can find some notes on it throughout the source code

    Since hints are "hacks to get around temporary workarounds inside the environment" the code is scattered about the various renderers where needed. It is also all subject to change!

Sign In or Register to comment.