Multiple viewports

Is it possible with JMonkey to have multiple viewports? I would like to have 4 different angle views of an object so it would be great. Sort of like creating 4 Canvas3D using Java3D.

Any ideas on this out there?  I'm trying to do the same thing, preferably without rendering to a texture. 

The LWJGLCamera.java class sets up the Viewport, which is what you want to change in GL.

It, in turn, does this through renderer.Camera/renderer.AbstractCamera.

At a first guess, I would assume that the way to render four views, is to create four Cameras, each with a different value of setViewport(). Note that the arguments go from 0 to 1 for left-to-right; they're not measured in pixels.

The Renderer has only a single camera object, so you probably need to do something fancy with Renderer.renderQueue(), calling it once for each camera, and re-implement the Renderer.displayBackBuffer() call – check BaseGame.render() for the specifics.

I just dealt with this myself, it was hell to figure out at first but I whittled it down to a pretty clean solution.



Here's the code I ended up using:


 
   public final void simpleRender()
  {
    renderer.clearBuffers();
   
    // First pass draws on the left.
    cam.resize(width/2, height);
    cam.setViewPort(0.0f, 1.0f, 0.0f, 1.0f);

    boolean bUseRenderPasses = true;

    if( bUseRenderPasses )
      pManager.renderPasses(renderer);
    else
      renderer.draw(rootNode);

    if (bStereo)
    {
      // Second pass on the right.
      cam.resize(width/2, height);
      cam.setViewPort(1.0f, 2.0f, 0.0f, 1.0f);

      // Shift the camera over a little.
      cam.setLocation(cam.getLocation().add(cam.getLeft().mult(-1.0f)));

      if( bUseRenderPasses )
        pManager.renderPasses(renderer);
      else
        renderer.draw(rootNode);
    }

    renderer.displayBackBuffer();
  }



I'm not sure why I had to resize the camera to the same size again, but it doesn't work unless I do.

You can test it out at http://www.cs.utexas.edu/users/aharp/vg

Just hit "cycle rendermode" to see the double displays.

Thank you both for your responses.



Tried out the Vision Generator, great work. The way the multiple viewports work is exactly what I'm looking for.  Thanks for taking the time to post the code.