Hi all,
I was wondering if anyone could give me a bit of help with JOGL applets. I’ve been looking on jogl-demos, but I can’t really find any good example code for what I’m trying to do. It’s fairly basic really: I have a JOGL app that looks like this:
public class Viewer extends Frame implements GLEventListener
{
public static void main(String[] args)
{
new Viewer();
}
public Viewer()
{
GLCanvas canvas = new GLCanvas();
canvas.addGLEventListener(this);
add(canvas);
setSize(100,100);
setLocation(200,0);
new Animator(canvas).start();
}
public void init(GLAutoDrawable drawable)
{
GL gl = drawable.getGL();
gl.glEnable(GL.GL_DEPTH_TEST);
...
}
public void reshape(GLAutoDrawable d, int x, int y, int w, int h)
{
GL gl = d.getGL();
...
gl.glViewport(0,0,w,h);
}
public void display(GLAutoDrawable drawable)
{
GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
...
}
}
And I want to convert this into an applet.
Firstly I guess I need to derive Viewer from JOGLAppletLauncher instead of Frame, and then implement init(), start(), stop() and destroy(). My problem is that I don’t quite understand how to map what I’ve got now onto that.
Firstly, I guess that I should attach the canvas in init():
public void init()
{
GLCanvas canvas = new GLCanvas();
canvas.addGLEventListener(this);
add(canvas);
setSize(100,100);
setLocation(200,0);
new Animator(canvas).start();
}
However, when it comes to init(GLAutoDrawable drawable), how should this be implemented, in particular how do I get a reference to the GL object? The same with display() and reshape(), again, how do I access the GL object? I’m also unsure if the Animator will work correctly in this way, maybe not…?
One problem I have is that I’m not getting much debug/output from running the applet through a browser, so it’s difficult to know why things aren’t working. Has anyone got any tips for doing this?
I’m pretty sure I’ve got the html correct and the jars are loading etc, but I really just need a few tips on the basic structure of the code just to get me started.
Thanks a lot,
Chris.