<p>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 <code>false</code> return value which would lead to a <code>System.exit</code>. I have no idea how I didn't catch this the last time round, but it now works with <em>Try 2</em>. That is:</p>

<pre><code>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();
    }
</code></pre>

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

CC BY-SA 4.0
2020-02-18T14:53:09.987Z
2020-02-18T14:53:09.987Z
Tare
<p>I have a working renderer implemented with Java in JOGL with <a href="https://jogamp.org/jogl/doc/NEWT-Overview.html" rel="nofollow noreferrer">NEWT</a>. 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.</p>

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

<pre><code>public static void initOpenGl()
{
    GLProfile.initSingleton();
}
</code></pre>

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

<pre><code>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();
}
</code></pre>

<hr>

<p><em>TRY 1</em></p>

<p>In my first attempt, I created a subwindow thus:</p>

<pre><code>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!");
}
</code></pre>

<p>Since the context is null however, an exception is thrown:</p>

<blockquote>
  <p>No OpenGL context current on this thread</p>
</blockquote>

<hr>

<p><em>TRY2</em></p>

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

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

<hr>

<p>Perhaps the question would be better stated as "how to create a second GL Context", I am not exactly sure.</p>

<opengl><java>
How to open and render in a second window with OpenGL / JOGL with NEWT
Tare
# How to open and render in a second window with OpenGL / JOGL with NEWT

(Asked by: username_0 on 2019-06-22)

I have a working renderer implemented with Java in JOGL with [NEWT](https://jogamp.org/jogl/doc/NEWT-Overview.html). 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.

**Tags:** opengl, java


---

## 1 answers

### Answer by username_0 on 2020-02-18. Score: 1 | Accepted answer

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.


---

