# Use 3D Graphics on Android for draw an .obj file offscreen

**URL:** https://discourse.processing.org/t/use-3d-graphics-on-android-for-draw-an-obj-file-offscreen/40483
**Category:** Processing for Android
**Created:** [January 6, 2023, 8:39am UTC](https://discourse.processing.org/t/use-3d-graphics-on-android-for-draw-an-obj-file-offscreen/40483 "2023-01-06T08:39:24Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mbbl33](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@mbbl33](https://discourse.processing.org/u/mbbl33)
#### Post date: [January 6, 2023, 8:39am UTC](https://discourse.processing.org/t/use-3d-graphics-on-android-for-draw-an-obj-file-offscreen/40483/1 "2023-01-06T08:39:24Z")

</div>

Hello all,

I am trying to draw an .obj file offscreen under Android.  
The image should then be passed to OpenCV for further use as a matrix.

In 2D the whole thing already works without problems.

```java
public class ObjDrawer extends PApplet {

    PGraphics buffer;
    PShape obj;
    int width;
    int height;

    public ObjDrawer(int width, int height) {
        this.width = width;
        this.height = height;
        setup();
    }

    @Override
    public void setup() {
        buffer = createGraphics(this.width, this.height, P3D);
        //obj = loadShape("Wuerfel_40mm.obj");
        noLoop();
    }

    public Mat testDraw() {
        buffer.beginDraw();
        buffer.background(255);
        buffer.ellipse(200, 200, 100, 100);
        //buffer.shape(obj);
        buffer.endDraw();
        return toMat(buffer.get());
    }

    Mat toMat(PImage image) {
        //source: https://gist.github.com/Spaxe/3543f0005e9f8f3c4dc5
        int w = image.width;
        int h = image.height;

        Mat mat = new Mat(h, w, CvType.CV_8UC4);
        byte[] data8 = new byte[w * h * 4];
        int[] data32 = new int[w * h];
        arrayCopy(image.pixels, data32);
        ByteBuffer bBuf = ByteBuffer.allocate(w * h * 4);
        IntBuffer iBuf = bBuf.asIntBuffer();
        iBuf.put(data32);
        bBuf.get(data8);
        mat.put(0, 0, data8);
        return mat;
    }

}

```

When using 3D, I now get the following error message:

```auto
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean processing.core.PGraphics.isGL()' on a null object reference
	at processing.core.PApplet.makeGraphics(PApplet.java:1584)
	at processing.core.PApplet.createGraphics(PApplet.java:1568)
	at Analyzer.ObjDrawer.setup(ObjDrawer.java:52)
	at Analyzer.ObjDrawer.<init>(ObjDrawer.java:45)
	at com.quickbirdstudios.opencvexample.MainActivity$cvCameraViewListener$1.onCameraFrame(MainActivity.kt:75)
	at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:392)
	at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:373)
	at java.lang.Thread.run(Thread.java:920)

```

In my research I read about a3d, this is missing for me. Since all the stuff I found regarding a3d was about 10 years old: has anything changed in this regard or has it been replaced or do I need to include this separately?

I have included Processing as in the tutorial on [https://android.processing.org/tutorials/android\_studio/index.html](https://android.processing.org/tutorials/android_studio/index.html)

integrated. I use Android Mode for Processing 3 4.3.0, because the mode manager in Processing 4 is currently broken.

many thanks in advance!

---

<div class="post-metadata">

### Author: ![erkosone](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@erkosone](https://discourse.processing.org/u/erkosone)
#### Post date: [January 6, 2023, 9:33pm UTC](https://discourse.processing.org/t/use-3d-graphics-on-android-for-draw-an-obj-file-offscreen/40483/2 "2023-01-06T21:33:55Z")

</div>

Update your Android\_mode to the latest version, you just have to open an Android project from the IDe and it will be downloaded automatically.

Here you have a project for you to open with your editor. It will automatically start downloading in android mode 😉

> **[sketch\_221222a.zip](https://www.dropbox.com/s/hgv4rsmm9kunwca/sketch_221222a.zip?dl=0)**
>
> Shared with Dropbox

---

<div class="post-metadata">

### Author: ![mbbl33](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@mbbl33](https://discourse.processing.org/u/mbbl33)
#### Post date: [January 7, 2023, 9:50am UTC](https://discourse.processing.org/t/use-3d-graphics-on-android-for-draw-an-obj-file-offscreen/40483/3 "2023-01-07T09:50:36Z")

</div>

Thanks already for the answer.  
When I open it in Processing 3, no update starts. In the contribution manager, no update is shown there either.  
When I try to open it in Processing 4, it just shows the error message that I should update my Android mode, and it switches back to Java mode.

Which version are we talking about? The one for Processing 4 4.5.0b2?  
It is unfortunately grayed out in P3 due to incompatibility, and in P4 the contribution manager for the modes does not work.  
Can I get the appropriate core.jar somewhere else?

---

<div class="post-metadata">

### Author: ![erkosone](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@erkosone](https://discourse.processing.org/u/erkosone)
#### Post date: [January 7, 2023, 10:01pm UTC](https://discourse.processing.org/t/use-3d-graphics-on-android-for-draw-an-obj-file-offscreen/40483/4 "2023-01-07T22:01:36Z")

</div>

Solo tienes que tener una version limpia de processing 4 en tu PC, “hablo de windows”, entonces abre el proyecto que te pase y automaticamente te saldrá un dialogo para descargar el Android mode ultima version.

---

<div class="post-metadata">

### Author: ![mbbl33](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@mbbl33](https://discourse.processing.org/u/mbbl33)
#### Post date: [January 8, 2023, 9:48am UTC](https://discourse.processing.org/t/use-3d-graphics-on-android-for-draw-an-obj-file-offscreen/40483/5 "2023-01-08T09:48:38Z")

</div>

I managed to update, but still get the same error. Does createGraphics() need the size() method before? I tried size() once in the first line of setup() and also tried it in settings(), in both cases I get the error that it is not in setting().
