# Extending PGraphicsJava2D: Space between triangles / vertices

**URL:** https://discourse.processing.org/t/extending-pgraphicsjava2d-space-between-triangles-vertices/14797
**Category:** Coding Questions
**Created:** [October 19, 2019, 11:48am UTC](https://discourse.processing.org/t/extending-pgraphicsjava2d-space-between-triangles-vertices/14797 "2019-10-19T11:48:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![companje](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/companje/32/2418_2.png) [@companje](https://discourse.processing.org/u/companje)
#### Post date: [October 19, 2019, 11:48am UTC](https://discourse.processing.org/t/extending-pgraphicsjava2d-space-between-triangles-vertices/14797/1 "2019-10-19T11:48:06Z")

</div>

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](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](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/bd8d9ae6415880c3027d2689160038cfca08bc4c.png)

```auto
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);
}

```

```auto
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();
  }
}

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [October 19, 2019, 11:57am UTC](https://discourse.processing.org/t/extending-pgraphicsjava2d-space-between-triangles-vertices/14797/2 "2019-10-19T11:57:11Z")

</div>

```auto
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?](https://discourse.processing.org/t/where-is-this-stroke-coming-from/14545) ,

---

<div class="post-metadata">

### Author: ![companje](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/companje/32/2418_2.png) [@companje](https://discourse.processing.org/u/companje)
#### Post date: [October 19, 2019, 1:23pm UTC](https://discourse.processing.org/t/extending-pgraphicsjava2d-space-between-triangles-vertices/14797/3 "2019-10-19T13:23:32Z")

</div>

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`:

```auto
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](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0347a431dada0af1257ad774bd39a928357148d2.png)

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [October 23, 2019, 1:34am UTC](https://discourse.processing.org/t/extending-pgraphicsjava2d-space-between-triangles-vertices/14797/4 "2019-10-23T01:34:15Z")

</div>

i only see it in P2D P3D working

```auto
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);
}

```
