2 glCanvas in a JFrame

Hi all,

I built a JFrame containing 2 glCanvases.
I linked each canvas with a different renderer, implementing the GLEventListener interface. Each renderer has its own Animator.

It doesn’t work : rendering is weird. It looks like parts of rendering are past to the other glCanvas.

Any ideas ? is this GLContext or multi-threading issue ?


/* Generated with neatbeans */
public class SelectorDialog extends javax.swing.JDialog {
....

    private GLCanvas canvas1;
    private GLCanvas canvas2;

    public GLCanvas getCanvas1() {
        return canvas1;
    }

    public GLCanvas getCanvas2() {
        return canvas2;
    }

}

public View1 implements GLEventListener {
...
}

public View2 implements GLEventListener {
...
}

public class MySelector extends Selector {

public MySelector() {

	GLCanvas canvas1 = getCanvas1();
	canvas1.setAutoSwapBufferMode(true);

	View1 view1 = new View1();
	canvas1.addGLEventListener(view1);
		
        FPSAnimator animator = new FPSAnimator( canvas1 , 60 );
        animator.setRunAsFastAsPossible(false);
        animator.start();
        
        GLCanvas canvas2 = getCanvas2();
        canvas2.setAutoSwapBufferMode(true);

	View2 view2 = new View2();
	canvas2.addGLEventListener(view2);
		
        FPSAnimator animator2 = new FPSAnimator( canvas2, 60 );
        animator2.setRunAsFastAsPossible(false);
        animator2.start();
        
        setVisible(true);
}

}

Which version of JOGL do you use? Have you tried to do the same thing with NEWT?

If you’re using GLEventListeners it shouldn’t be a multi-threading issue, the two canvases would just take turns. It’s likely that the two GLCanvases are being laid out incorrectly (and then overlapping heavy-weight components == bad) or the implementation of GLCanvas assumes that it can take over the entire window when it’s rendering (but I don’t know).

Can you post the actual code that adds the canvases to your JDialog? I’ll give it a shot on my computer.

do you need to use 2 canvas’s? Why not just use multiple view ports?

Thanks all for your replies (and sorry for my approximate english writing)

It looks ok now ; my renderers were wrong and not dealing properly shared datas ; no troubles with multi-threading or so ! The code in my first post is ok. I’m sorry for making you waste your time.

I saw a previous thread on the same kind of trouble ; it was said in it to use a single animator for many canvases, and to deactivate autoSwapBuffering.
By the way, my GUI works with autoSwapBuffering enabled and with 2 animators, but that was an interesting way to explore.
However, I dont really understand the behaviour of all this. Where could I find some ressources on the subject ? How buffer swaping works or should work in a multi canvases context ?

I worked and thought on such a solution. However technics are much more complicated (i’m quite a beginner using opengl and dont want to go to far in it for now). And in my case, the idea was to create a GUI that mixes 3d rendering and other swing components (buttons, trees … ) so that i dont have to re-create a 3d JTree-like component. I searched for a kind of jogl GUI “library”, but couldn’t find one.

Another question I cant find no response is about the “theory and technics” on the popup windows and dialogs in games.
Let’s take Minecraft for example ; when you open the main menu, or the “material” menu : how does it work ? I guess he doesnt use a JFrame or JDialog … Does he render the menu or dialog in a texture and rendering this texture over the main scene ? But with non modal dialogs how should this work ?

Thanks in advance

Don’t disable auto swap buffer mode if you use JOGL 2.0 beta as it hugely increases the memory consumption.