Render to simultaneous graphic contexts OGL in Java and Android mode

edited April 2014 in Library Questions

I'd like to create a library that extends the standard P2D OGL graphics object with additional properties. The idea is to enable 2D sketches to expose some secondary non-rendered properties such as material and depth information. These additional properties would be used to later create 3D geometry, but the 3D geometry is not needed or wanted for visualization (at least not yet).

To keep it simple, I'm starting with a simple 2D sketch such as:

  void draw() {
    background(0);
    noFill();
    stroke(128, 255, 128);
    rect(width*0.25, height*0.1, width * 0.5, height * 0.8);
  }

I want to enable the sketch to include depth and material (probably coded as a color component) such that the above sketch could be extended as such:

  void draw() {
    background(0);
    noFill();
    stroke(128, 255, 128);
    depthStroke(128); // might map to color (128,128,128) 
    rect(width*0.25, height*0.1, width * 0.5, height * 0.8);
  }

In my contrived example above, I'd like to have the standard P2D renderer showing the green rectangle and also be able to capture the same render, but with stroke color replaced by my "depthStroke" color. This would, in the end, enable me to create two images: one that is just the rendered image and another image that is essentially depth information for each pixel. From those two images, I'd later generate 3D geometry.

My goals are:

  • Minimal changes to existing 2D sketches
  • Works in web (Javascript), desktop (Java), and mobile (Android) modes

I've tried a number of things including the Recorder on PGraphics (doesn't seem to play nicely with OGL), doing this all in the sketch using off-screen buffers (works, but means people would have two re-write their sketches or add lots of supporting code), possibly adding a new FrameBuffer (FrameBuffer is package local so I can't get to it), etc. In the end, I haven't found a way to accomplish my goal. Right now I'm considering extending PGraphicsOpenGL (P2D that is) and:

  • Capture each and every call to begin/endShape and record the information
  • Replay the calls when safe to do so (at the end of endDraw?)

This approach just seems overly complex and I'm hoping someone out there has a better idea. :)

Sign In or Register to comment.