GLCanvas & JSplitPane

Is it possible to put a couple of GLCanvases inside a JSplitPane?

GLCanvas is a heavy weight so chances are it won’t play nice with a JSplitPane. Use GLJPanel - its slow but for an editor it should be adequate.

Thats not really an option - speed it the reason for wanting to use GLCanvas in the first place

I’m currently using a GCCanvas in a JSplitPane
Seems to work fine
I’m quite the newbie so I may be doing something I shouldn’t, but it works for me
I can send some code snippets if you want
check this out

http://www.drobbins.net/SpriteIIServer/SpriteII.html

hope it works from outside my house

Dave

BTW, ignore the stuff in the left pane, it’s not functional

Are you putting them in directly or using a wrapper of some kind?

Originally, my app had nothing to do with jogl. It was a splitpane with a tree on the left, and when you clicked on any leaf in the tree it displayed the appropriate panel on the right (other leaves would show tables with data from database if db machine was online) . when I started playing with jogl I just created a new panel to play with. Here’s the code for my jogl panel. I cut out a lot of the unrelevent stuf, it was to long to post, I hope it’s not unreadably. I still have a really wierd problem with loading textures, with it made into a webstart app it loads the textures correctly on some machines and not on others. The cubes should have a stained glass image mapped onto them, did you see that or just mono-color??

public class JOGL extends JPanel {
class MyCanvas implements GLEventListener{

public void init(GLDrawable drawable){

  try{
      GL gl = drawable.getGL();
      GLU glu = drawable.getGLU();
      glConfig(gl);
      addLighting(gl);
      setupView(glu);
      gl.glEnable(GL.GL_NORMALIZE);
      gl.glEnable(GL.GL_TEXTURE_2D);
      gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT,gl.GL_NICEST);

      //setup textures
      texture = genTexture(gl);
      gl.glBindTexture(GL.GL_TEXTURE_2D, texture);
      BufferedImage img = readPNGImage("images/glass.png");
      makeRGBTexture(gl, drawable.getGLU(), img, GL.GL_TEXTURE_2D, false);
      gl.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MIN_FILTER,GL.GL_LINEAR);
      gl.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MAG_FILTER,GL.GL_LINEAR);
      gl.glColor4f(1.0f,1.0f,1.0f,0.5f);                  // Full Brightness, 50% Alpha ( NEW )
      gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
      gl.glEnable(GL.GL_BLEND);            // Turn Blending On
    gl.glDisable(GL.GL_DEPTH_TEST);      
  }catch( Exception e)
  {
    System.err.println("Failed in init: " + e.toString() );   
  }
  System.out.println("==== init stage done ====");

}
private void glConfig(GL gl){
gl.glShadeModel(GL.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
}
private void addLighting(GL gl){
float pos[] = {0.0f, 10.0f, 10.0f, 1.0f };
float LightAmbient[]= { 0.1f, 0.1f, 0.1f, 1.0f };
float LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };
gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, pos);
gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, LightDiffuse);
gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT,LightAmbient);
gl.glEnable(GL.GL_CULL_FACE);
gl.glEnable(GL.GL_LIGHTING);
gl.glEnable(GL.GL_LIGHT0);
gl.glEnable(GL.GL_DEPTH_TEST);
}
private void setupView(GLU glu){
glu.gluLookAt(0.0f,0.0f,20.0f,0.0f,0.0f,-1.0f,0.0f,1.0f,0.0f);
}

public void reshape(GLDrawable drawable, int x, int y, int width, int height) {
float h = (float)height / (float)width;

  GL gl = drawable.getGL();

  gl.glMatrixMode(GL.GL_PROJECTION);
  System.err.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR));
  System.err.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER));
  System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION));
  System.err.println();
  System.err.println("glLoadTransposeMatrixfARB() supported: " +
                     gl.isFunctionAvailable("glLoadTransposeMatrixfARB"));
  if (!gl.isFunctionAvailable("glLoadTransposeMatrixfARB")) {
    // --- not using extensions
    gl.glLoadIdentity();
  }
  else {
    // --- using extensions
    final float[] identityTranspose = new float[] {
      1, 0, 0, 0,
      0, 1, 0, 0,
      0, 0, 1, 0,
      0, 0, 0, 1
    };
    gl.glLoadTransposeMatrixfARB(identityTranspose);
  }
  gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
  gl.glMatrixMode(GL.GL_MODELVIEW);
  gl.glLoadIdentity();
  gl.glTranslatef(0.0f, 0.0f, -40.0f);

}
// ================= DISPLAY ============ //
public void display(GLDrawable drawable) {

}

public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
/** Creates new form JOGL2 */

}
/** Creates new form JOGL */
public JOGL(Main main, DBWrapper db) {
super(main, db);
initComponents();

    xSlider.setBackground(bgcolor);
    ySlider.setBackground(bgcolor);
    zSlider.setBackground(bgcolor);
    iSlider.setBackground(bgcolor);
    jSlider.setBackground(bgcolor);
    kSlider.setBackground(bgcolor);
    
   
   
    GLCapabilities glCape = new GLCapabilities();
    glCape.setDoubleBuffered(true);
    glCape.setHardwareAccelerated(true);
    glCape.setOffscreenRenderToTexture(true);
    canvas = GLDrawableFactory.getFactory().createGLCanvas(glCape);
    MyCanvas = new MyCanvas();
    canvas.addGLEventListener(MyCanvas);
    jPanel3.add(canvas);
    GL gl = canvas.getGL();
    GLU glu = canvas.getGLU();
    gl.glEnable(GL.GL_NORMALIZE);
    
    gl.glShadeModel(GL.GL_SMOOTH);              // Enable Smooth Shading
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);    // Black Background
    gl.glClearDepth(1.0f);                      // Depth Buffer Setup
  //  gl.glEnable(GL.GL_DEPTH_TEST);              // Enables Depth Testing
  //  gl.glDepthFunc(GL.GL_LEQUAL);
    setSize(800,650);
  //  ClassLoader c1=this.getClass().getClassLoader();
  //  URL url=c1.getResource("images/ford.gif");
}



// Variables declaration - do not modify
private javax.swing.JSlider iSlider;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JSlider jSlider;
private javax.swing.JSlider kSlider;
private javax.swing.JSlider xSlider;
private javax.swing.JSlider ySlider;
private javax.swing.JSlider zSlider;
// End of variables declaration

public GLCanvas canvas;
public MyCanvas MyCanvas;
public java.awt.Color bgcolor = new java.awt.Color(102, 153, 204);

}

I left out the part for how I build the scene but it shows how I created the GLCanvas

"The cubes should have a stained glass image mapped onto them, did you see that or just mono-color?? "

Sorry, it didn’t run for me at all when I tried it :’(

No exception text - it seemed to fail before even starting up the JVM (probably a network issue?)

Placing the canvas in a JPanel solved most of my splitpane issues :slight_smile: