I’d like to share the good news with you folks
that I’ve successfully ported our app from
JOGL to JSR-231 and it’s working just fine.
Some of you may already know from my previous
posts here that I’ve been requesting full manual
mode of JOGL for a long time. JSR-231 delivers
that and below is a bare minimum app that
shows how to do that in JSR-231. Ken, feel free
to use the code if you think it’s useful as a demo.
`package test;
import java.awt.Canvas;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Random;
import javax.media.opengl.*;
/**
-
Testing JSR-231 in manual mode.
-
- Custom AWT component
-
- Manual context handling
-
- Custom rendering thread
*/
public class ManualMode extends Canvas implements Runnable
{
GLDrawable drawable;
GLContext context;
boolean run = true;
Object wait = new Object();
public ManualMode()
{
drawable = GLDrawableFactory.getFactory().getGLDrawable(this, new GLCapabilities(), null);
context = drawable.createContext(null);Frame frame = new Frame("JSR-231 test: manual mode"); frame.add(this); frame.setSize(640, 480); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { run = false; try { System.err.println(Thread.currentThread().getName() + ": waiting for OpenGL thread"); synchronized(wait) { wait.wait(); } System.err.println(Thread.currentThread().getName() + ": notified"); } catch(InterruptedException ex) {} System.exit(0); } }); new Thread(this, "OpenGL thread").start();
}
public void addNotify()
{
super.addNotify();
drawable.setRealized(true);
}public void removeNotify()
{
drawable.setRealized(false);
super.removeNotify();
}public void run()
{
context.makeCurrent();GL gl = context.getGL(); Random random = new Random(); while(run) { gl.glClearColor(random.nextFloat(), random.nextFloat(), 1, 1); gl.glClear(GL.GL_COLOR_BUFFER_BIT); drawable.swapBuffers(); } context.release(); context.destroy(); drawable.setRealized(false); System.err.println(Thread.currentThread().getName() + ": notifying waiting thread"); synchronized(wait) { wait.notifyAll(); } System.err.println(Thread.currentThread().getName() + ": exiting");
}
/**
-
@param args
*/
public static void main(String[] args)
{
new ManualMode();
}
}
`
- Custom rendering thread