# G4P ViewListener imported obj render problem

**URL:** https://discourse.processing.org/t/g4p-viewlistener-imported-obj-render-problem/13794
**Category:** Libraries
**Created:** [September 4, 2019, 10:12am UTC](https://discourse.processing.org/t/g4p-viewlistener-imported-obj-render-problem/13794 "2019-09-04T10:12:01Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mala](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@mala](https://discourse.processing.org/u/mala)
#### Post date: [September 4, 2019, 10:12am UTC](https://discourse.processing.org/t/g4p-viewlistener-imported-obj-render-problem/13794/1 "2019-09-04T10:12:02Z")

</div>

I’m getting a strange effect when trying to render stroke & fill on an imported obj, the stroke appears to only be rendered once at first frame , almost as an orthographic projection, this stroke rotates with the box as expected but is flat.

As a simple example, take the G4P\_ViewListeners example file, import a simple .obj and set up some shading:

```auto
PShape box;
void settings() {
  size(600, 380, P2D);
}

void setup() {
  box = loadShape("data/"+"box.obj");
  box.setStroke(true);
  box.setStroke(color(42, 100, 138));
  box.setStrokeWeight(2.0f);
  box.setFill(color(50, 50, 50));

```

and replace the box(80) in the “ShowBox” tab with the pshape:

```auto
 v.beginDraw();
    //v.ambientLight(100, 100, 10);
    //v.directionalLight(255, 255, 0, 0.5f, 1, -2f);
    v.background(0);
    v.translate(v.width/2, v.height/2);
    v.rotateX(0.19f * a);
    v.rotateY(1.101f * a);
    v.rotateZ(1.357f * a);
    //v.fill(255, 200, 128);
    //v.stroke(255, 0, 0);
    //v.strokeWeight(4);
    v.shape(box);
    //v.box(80);
    a += delta;
    v.endDraw();

```

Could be this is not a problem with G4P as such but inherited from PGraphics… though I’ve been able to render stroke and fill on an imported obj when not using G4P.

Has anyone any ideas?

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [September 4, 2019, 10:50am UTC](https://discourse.processing.org/t/g4p-viewlistener-imported-obj-render-problem/13794/2 "2019-09-04T10:50:28Z")

</div>

The GView control uses a Processing PGraphic object as a buffer for the display. The buffer is either JAVA2D, P2D or P3D depending on what you passed as parameters when you created the control. So in your code above `v` is a PGraphics3D object.

You might try adding the line

```auto
v.hint(DISABLE_OPTIMIZED_STROKE);

```

after the background statement and see if that helps.

---

<div class="post-metadata">

### Author: ![mala](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@mala](https://discourse.processing.org/u/mala)
#### Post date: [September 4, 2019, 11:12am UTC](https://discourse.processing.org/t/g4p-viewlistener-imported-obj-render-problem/13794/3 "2019-09-04T11:12:45Z")

</div>

@quark  
thanks for the suggestion, unfortunately that doesn’t seem to have helped ☹

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [September 4, 2019, 11:29am UTC](https://discourse.processing.org/t/g4p-viewlistener-imported-obj-render-problem/13794/4 "2019-09-04T11:29:58Z")

</div>

Have you tried drawing the shape straight onto the screen, bypassing G4P. Any solution should be applied in the listener.

To be honest I don’t think the problem is with G4P because the GView control uses Processing drawing commands with Processing rendering modes.

---

<div class="post-metadata">

### Author: ![mala](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@mala](https://discourse.processing.org/u/mala)
#### Post date: [September 4, 2019, 11:49am UTC](https://discourse.processing.org/t/g4p-viewlistener-imported-obj-render-problem/13794/5 "2019-09-04T11:49:28Z")

</div>

Have found the solution, the sketch itself must be P3D in order for the stroke to be rendered correctly i.e :

```auto
void settings() {
  size(600, 380, P3D);
}

```

Cheers,  
mala
