Hi!
Although I have some experience in Opengl using C++ I’m a completely newcomer to Java and JOGL.
I has trying to build a very simple applet using JOGL, and it was working just fine with beta 4, but know that I’ve upgraded my JOGL version to beta 5 I’m unable to execute the following chunk of code within the browser (in eclipse it works fine)
try
{
Class c = Class.forName("GLPanel1");
JPanel panel = (JPanel) c.newInstance();
this.getContentPane().add(panel);
}
catch (Exception e)
{
joglSupport = false;
}
It keeps cathing the exception…
I only have one JVM installed and the JOGL jar and dlls are in the correct place in the JRE. I don’t have it in the JDK.
Here is the full source:
import javax.swing.*;
public class JOGLTutorialApplet1 extends JApplet
{
public void init()
{
boolean joglSupport = false;
try
{
Class.forName("net.java.games.jogl.GLCanvas");
joglSupport = true;
}
catch(ClassNotFoundException e)
{
joglSupport = false;
}
if(joglSupport)
{
try
{
Class c = Class.forName("GLPanel1");
JPanel panel = (JPanel) c.newInstance();
this.getContentPane().add(panel);
}
catch (Exception e)
{
joglSupport = false;
}
}
if(!joglSupport)
{
this.getContentPane().add(new JLabel("JOGL not installed"));
}
}
}
import net.java.games.jogl.*;
import javax.swing.*;
public class GLPanel1 extends JPanel implements GLEventListener
{
private GLCanvas canvas;
/**
* Constructor of the Panel.
* The constructor creates a GLCanvas and then adds it to itself.
*/
public GLPanel1()
{
super();
/**
* First we create the capabilities for our canvas
*/
GLCapabilities capabilities = new GLCapabilities();
capabilities.setHardwareAccelerated(true); //We want hardware accelleration
capabilities.setDoubleBuffered(true); //And double buffering
/**
* Then we create the canvas.
*/
canvas=GLDrawableFactory.getFactory().createGLCanvas(capabilities);
/**
* We add the eventlistener, so that the display will be updated at the appropriate times.
*/
canvas.addGLEventListener(this);
/**
* Finally we add the canvas and set its size
*/
this.add(canvas);
this.setSize(640,480);
canvas.setSize(640,480);//We want the JPanel and the GLCanvas to have the same size
canvas.setVisible(true);//This is somehow necessary
}
/**
* The init method will be called when the GLCanvas is constructed.
* Here we put the basic settings that will only be called once.
* @param glDrawable
*/
public void init(GLDrawable glDrawable)
{
GL myGL=glDrawable.getGL();//Get the GL object from glDrawable
myGL.glClearColor (0.2f, 0.5f, 0.8f, 0.0f);
myGL.glShadeModel(GL.GL_FASTEST);
}
/**
* This is the function where the drawing is done.
* This method is called everytime repaint() is called.
* JOGL uses Javas events, which makes it a lot easier to use.
* @param glDrawable
*/
public void display(GLDrawable glDrawable)
{
GL myGL=glDrawable.getGL();
myGL.glClear(GL.GL_COLOR_BUFFER_BIT);
myGL.glColor3f(0.2f, 0.6f , 0.5f);
myGL.glBegin(GL.GL_QUADS);
myGL.glVertex3f(-50,50,0);
myGL.glVertex3f(50,50,0);
myGL.glVertex3f(50,-50,0);
myGL.glVertex3f(-50,-50,0);
myGL.glEnd();
}
/**
* Reshape will be called everytime the canvas changes shape.
* This is a good place the MATRIX setup if you want the 'camera' settings to change when the display is resized.
* @param glDrawable
* @param i
* @param i1
* @param i2
* @param i3
*/
public void reshape(GLDrawable glDrawable, int i, int i1, int i2, int i3)
{
GL myGL=glDrawable.getGL();
int width=canvas.getWidth();
int height=canvas.getHeight();
myGL.glMatrixMode(GL.GL_PROJECTION);
myGL.glLoadIdentity();
myGL.glOrtho(-width/2,width/2,-height/2,height/2,-10,10);
}
public void displayChanged(GLDrawable glDrawable, boolean b, boolean b1)
{
}
}
Hope someone can help me.
Thanx,
hellder.