Jogl & Swing

Anyone got even a simple jogl program to run with a Swing JFrame ?

I tried changing the Frame constructor in the gears demo to

JFrame frame = new JFrame()
frame.getRootPane.add( canvas )

The Frame appears on the screen but nothing is rendered, it appears that none of the GearRendered methods are called :’(

Try:

JFrame frame = new JFrame();
frame.getContentPane().add( canvas );

I have it working ok, but be careful with rearranging components - the access violation I described in another thread also crops up if i try and resize the frame after it is initially visible when i’m using a border layout. Hopefully these teething problems will be ironed out soon.

OK, I’ve found the cause of the problem I was seeing…

When using a awt.Frame as the container the jogl GLEventListener init is called when the frame is shown.

When using a JFrame as the container the GLEventListener is not called when the frame is shown. Adding an Animator to the canvas forces the initialisation and everything renders correctly.

I’ll check the docs carefully and figure out if this is a bug or a feature :wink:

Sounds like a bug. Please boil it down to a small test case and file an issue on http://jogl.dev.java.net/ .

btw where are the docs for JOGL? I’m playing around with it and have added it to a JFrame with some mix results.

  1. I notice some skips in the rendering where my 2d frame buffer shows for a split second every now and then. (the rendering loop for the 2d buffer is turned off when I switch over to the glCanvas).

  2. I’m also having trouble closing down the glCanvas. I’m calling dispose on it and trying to switch back to my 2d rendering pipe with not much luck. It appears the canvas is being disposed but setting focus back to my JFrame and starting the 2d rendering loop back up isn’t doing the trick.

Also should I remove my mouse listeners and keyboards listeners from my original Jframe? and reset them after I dipose of the glcanvas. It works without doing this so I’m wondering if it is a good idea or not.

The documentation is currently minimal. There is an overview guide in the source tree at doc/userguide/index.html. The javadoc, however, should be pretty complete at least for the core JOGL package.

The issues around disposing of a GLCanvas haven’t been 100% thought through yet. I believe Pepijn Van Eeckhoudt (pepijnve on java.net) is looking into bringing GL4Java’s disposal handling into JOGL.

Without more knowledge of how your application is set up I can’t guess why you might be seeing flickering of your 2D display over your 3D one.