Login  Register

Re: Multiple Canvas In Same JFrame

Posted by gouessej on Aug 30, 2015; 7:46am
URL: https://forum.jogamp.org/Multiple-Canvas-In-Same-JFrame-tp4035177p4035178.html

Hi

Your code is poorly written, you mix up everything, you create a class that uselessly extends GLCanvas and that creates 2 canvases. System.exit(0) should be necessary only if you use Java Webstart. In my humble opinion, you should put the GLEventListener into a separate class and read some tutorials about Swing as your JFrame uses a BorderLayout by default then you should rather write:
frame.getContentPane().add(upperCanvas, BorderLayout.NORTH);
frame.getContentPane().add(lowerCanvas, BorderLayout.SOUTH);

Replace glu = new GLU();   by glu = GLU.createGLU(gl), otherwise your instance of GLU will support a tiny subset of GLU and throw unsupported operation exceptions whereas it is easy to avoid.

I wrote a simple example in which I put everything into the same class but I did it that way to keep it simple, it doesn't mean that it should be done in real programs:
https://gist.github.com/gouessej/3420e2b6f632efdddf98

There are some modern examples here:
http://jogamp.org/git/?p=jogl-demos.git;a=blob;f=src/demos/es2/RawGL2ES2demo.java;hb=HEAD
https://github.com/elect86/jogl-samples/blob/master/jogl-samples/src/helloTriangle/HelloTriangle.java
Julien Gouesse | Personal blog | Website