how do I set quad buffering with jogl 2.0

Posted by tony danza on Game Development See other posts from Game Development or by tony danza
Published on 2012-09-19T11:27:46Z Indexed on 2012/09/19 21:51 UTC
Read the original article Hit count: 299

Filed under:
|

I'm trying to create a 3d renderer for stereo vision with quad buffering with Processing/Java. The hardware I'm using is ready for this so that's not the problem. I had a stereo.jar library in jogl 1.0 working for Processing 1.5, but now I have to use Processing 2.0 and jogl 2.0 therefore I have to adapt the library.

Some things are changed in the source code of Jogl and Processing and I'm having a hard time trying to figure out how to tell Processing I want to use quad buffering.

Here's the previous code:

  public class Theatre extends PGraphicsOpenGL{
  protected void allocate() {
  if (context == null)
  {
    // If OpenGL 2X or 4X smoothing is enabled, setup caps object for them
    GLCapabilities capabilities = new GLCapabilities();
    // Starting in release 0158, OpenGL smoothing is always enabled
    if (!hints[DISABLE_OPENGL_2X_SMOOTH])
    {
      capabilities.setSampleBuffers(true);
      capabilities.setNumSamples(2);
    }
    else if (hints[ENABLE_OPENGL_4X_SMOOTH])
    {
      capabilities.setSampleBuffers(true);
      capabilities.setNumSamples(4);
    }


    capabilities.setStereo(true);

    // get a rendering surface and a context for this canvas
    GLDrawableFactory factory = GLDrawableFactory.getFactory();

    drawable = factory.getGLDrawable(parent, capabilities, null);

    context = drawable.createContext(null);
    // need to get proper opengl context since will be needed below
    gl = context.getGL();
    // Flag defaults to be reset on the next trip into beginDraw().
    settingsInited = false;

  }
  else
  {
    // The following three lines are a fix for Bug #1176
    // http://dev.processing.org/bugs/show_bug.cgi?id=1176
    context.destroy();
    context = drawable.createContext(null);
    gl = context.getGL();
    reapplySettings();
  }
}

}

This was the renderer of the old library. In order to use it, I needed to do size(100, 100, "stereo.Theatre"). Now I'm trying to do the stereo directly in my Processing sketch. Here's what I'm trying:

PGraphicsOpenGL pg = ((PGraphicsOpenGL)g);
pgl = pg.beginPGL();
gl = pgl.gl;
glu = pg.pgl.glu;
gl2 = pgl.gl.getGL2();

GLProfile profile = GLProfile.get(GLProfile.GL2);
GLCapabilities capabilities = new GLCapabilities(profile);

capabilities.setSampleBuffers(true);
capabilities.setNumSamples(4);
capabilities.setStereo(true);

GLDrawableFactory factory = GLDrawableFactory.getFactory(profile);

If I go on, I should do something like this:

drawable = factory.getGLDrawable(parent, capabilities, null);

but drawable isn't a field anymore and I can't find a way to do it. How do I set quad buffering?

If I try this:

gl2.glDrawBuffer(GL.GL_BACK_RIGHT);

it obviously doesn't work :/

Thanks.

© Game Development or respective owner

Related posts about opengl

Related posts about jogl