Extending PGraphicsJava2D: Space between triangles / vertices

Hello,

When extending PGraphicsJava2D (as described by @GoToLoop on the old forum
https://forum.processing.org/two/discussion/16314/pshape-inside-a-class-or-extend-pshape#Item_4 from) and drawing a TRIANGLE_STRIP I get space between the triangles as you can see in the following image. I’m very sure it is not the stroke, it’s really showing the background below it. The built-in ellipse function doesn’t have this problem.

Any suggestions?

TriangleStriptProblem

Layer layer;

void setup() {
  size(300, 300, P2D);
  layer = new Layer(this, 300, 300);
  layer.render(); //only render once
}

void draw() {
  background(128);
  image(layer, mouseX, mouseY);
}
import processing.awt.PGraphicsJava2D;

class Layer extends PGraphicsJava2D {   //or PGraphics2D for other renderer

  Layer(PApplet applet, int w, int h) {
    setParent(applet);
    setPrimary(false);
    setPath(applet.dataPath(""));
    setSize(w, h);
  }

  void render() {
    beginDraw();
    clear();
    fill(255);
    noStroke();

    //Problem: triangle strip shows 'holes' in between the parts the strip is made of.
    beginShape(TRIANGLE_STRIP);
    vertex(30, 75);
    vertex(40, 20);
    vertex(50, 75);
    vertex(60, 20);
    vertex(70, 75);
    vertex(80, 20);
    vertex(90, 75);
    endShape();

    ellipse(150, 150, 100, 100);
    endDraw();
  }
}
1 Like
void setup() {
  size(300, 300, P2D);
  layer = new Layer(this, 300, 300);
  layer.render(); //only render once
  noSmooth();                               // does the trick
}

see also
Where is this stroke coming from? ,

1 Like

Thanks @kll for the workaround. Would the only way be to disable smoothing when using PGraphicsJava2D? The result doesn’t look so nice in that case…

I simplified the example to show that it not only happens when extending from PGraphicsJava2D but also when using it through createGraphics:

PGraphics pg = createGraphics(500,500,JAVA2D);

size(500,500);
smooth();
background(128);

pg.beginDraw();
pg.clear();
//pg.background(128,0); //I hoped this helped so the renderer knew how to blend with the background but it doesn't.
pg.noStroke();
pg.beginShape(TRIANGLE_STRIP);
pg.vertex(30, 75);
pg.vertex(40, 20);
pg.vertex(50, 75);
pg.vertex(60, 20);
pg.vertex(70, 75);
pg.vertex(80, 20);
pg.vertex(90, 75);
pg.endShape();

pg.ellipse(150, 150, 100, 100);
pg.endDraw();

image(pg,0,0);

TriangleStriptProblem2

1 Like

i only see it in P2D P3D working

PShape pg,circ;

void setup() {
  size(500, 500,P2D);//FX2D);//P3D);//P2D);//JAVA2D);
  //noSmooth();
  make_shapes();
  noStroke();
}

void make_shapes() {
  pg = createShape();
  pg.beginShape(TRIANGLE_STRIP);
  pg.noStroke();
  //pg.stroke(255);
  pg.vertex(30, 75);
  pg.vertex(40, 20);
  pg.vertex(50, 75);
  pg.vertex(60, 20);
  pg.vertex(70, 75);
  pg.vertex(80, 20);
  pg.vertex(90, 75);
  pg.endShape();
  
  
  circ = createShape(ELLIPSE,150, 150, 100, 100);
  circ.setStroke(255);

}

void draw() {
  background(128);
  shape(pg, 0, 0);
  shape(circ, 0, 0);
}