Login  Register

How do I create second GL context?

Posted by kitfox on Nov 21, 2011; 9:14pm
URL: https://forum.jogamp.org/How-do-I-create-second-GL-context-tp3526076.html

I've written a program that builds a scenegraph and is able to render it to a JGLPanel.

I want to create a feature that can also capture images to render them offscreen.  I need to figure out how to create a second GLAutoDrawable in order to do this.  I was thinking of using PBuffers, but am open to any option that works.  

Because of the way my program is architected, the bit of the code that does the actual image capture should not be able to touch the JGLPanel in any way.  What I'm looking for is a way to create a surface I can draw to without having to first create a JGLPanel or JGLCanvas.

I tried the following (basing it off the HDR.java example code), but the getGL() call returns null:

[code]
        GLDrawableFactory fact = GLDrawableFactory.getFactory(GLProfile.getDefault());
        GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
        caps.setOnscreen(false);
        caps.setPBuffer(true);
        caps.setDoubleBuffered(false);
        GLPbuffer pbuf = fact.createGLPbuffer(null, caps, null, width, height, null);

        pbuf.getGL();  //Returns null
[/code]

How can I write this so that I have a live context I can render with?