How to open and render in a second window with OpenGL / JOGL with NEWT I have a working renderer implemented with Java in JOGL with NEWT. Now I want to implement a Material Editor which should run in a second window. However I can't get a second window up and render in it.

My main window is implemented as follows:
I have a class Backend which implements the GLEventListener. The two important methods are:

public static void initOpenGl()
{
    GLProfile.initSingleton();
}


which is called before anything else happens on start up and, to create the window itself

public void createWindow(int windowWidth, int windowHeight, boolean isFullscreen, String windowTitle
        , Program program)
{
    GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL3));
    caps.setBackgroundOpaque(false);
    glWindow = GLWindow.create(caps);

    glWindow.setTitle(windowTitle);
    glWindow.setSize(windowWidth, windowHeight);
    glWindow.setUndecorated(false);
    glWindow.setPointerVisible(true);
    glWindow.setVisible(true);

    m_program = program;
    glWindow.addGLEventListener(this);
    glWindow.addKeyListener(m_program);
    glWindow.addMouseListener(m_program);
    m_program.setBackend(this);

    Animator animator = new Animator();
    animator.add(glWindow);
    animator.start();
}




TRY 1

In my first attempt, I created a subwindow thus:

public void createSubWindow(int windowWidth, int windowHeight, boolean isFullscreen, String windowTitle
        , Program program)
{

    Display display = NewtFactory.createDisplay("mystring");
    display.addReference();

    Screen screen = NewtFactory.createScreen(display, 0);
    screen.addReference();

    GLProfile profile = GLProfile.get(GLProfile.GL3);
    GLCapabilities caps = new GLCapabilities(profile);
    GLWindow window = GLWindow.create(screen, caps);
    //the following line does not work, context is null
    GLContext context = window.createContext(GLContext.getCurrent());

    window.setSize(windowWidth, windowHeight);
    window.setVisible(true);
    window.setTitle(windowTitle);

    System.out.println(windowTitle + " window is open!");
}


Since the context is null however, an exception is thrown:


  No OpenGL context current on this thread




TRY2

In my second try I created a SubWindow class much like the Backend class, which implements GLEventListener and has the same createWindow method. This throws a different exception:


  com.jogamp.opengl.GLException: Caught ThreadDeath: null on thread main-Display-.windows_nil-1-EDT-1-AWTAnimator#01




Perhaps the question would be better stated as "how to create a second GL Context", I am not exactly sure.
So after letting this lie for quite a while, I just came back to it. Turns out, the error was in my code with a faulty false return value which would lead to a System.exit. I have no idea how I didn't catch this the last time round, but it now works with Try 2. That is:

public class SubWindow implements GLEventListener
{
    GLWindow glWindow;
    Program m_program;

    public void createSubWindow(int windowWidth, int windowHeight, boolean isFullscreen, String windowTitle
            , Program program)
    {
        GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL3));
        caps.setBackgroundOpaque(false);
        glWindow = GLWindow.create(caps);

        glWindow.setTitle(windowTitle);
        glWindow.setSize(windowWidth, windowHeight);
        glWindow.setUndecorated(false);
        glWindow.setPointerVisible(true);
        glWindow.setVisible(true);

        m_program = program;
        glWindow.addGLEventListener(this);
        glWindow.addKeyListener(m_program);
        glWindow.addMouseListener(m_program);

        Animator animator = new Animator();
        animator.add(glWindow);
        animator.start();
    }


Where the Program is one of my own classes handling the logic and the SubWindow class additionally implements the required init, display, etc. methods.