From: Frank A N. <tn...@ju...> - 2001-12-10 17:14:58
|
To All, I am just trying to how the GLJPanel and GLAnimJPanel works. I (like other posts, with no clear answer) am getting GLJPanel: problem in use() method message went executing a GL4Java program using a GLJPanel. Here is the complete source code. All I did is try to take Lesson 1 of the NeHe GL port lesson (http://dev.knowledgeassociates.com/hodglim/nehe/nehe.shtml) and use a GLJAnimJPanel with it. I also tried it with a GLJPanel with the same result. Any help would be greatly appreciated. Thanks Tony import java.applet.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import gl4java.GLContext; import gl4java.awt.GLAnimCanvas; import gl4java.swing.*; public class Lesson1 extends Applet { renderCanvas canvas = null; /** * void init() * * Initialise the applet. */ public void init() { setLayout(new BorderLayout()); canvas = new renderCanvas(); add("Center", canvas); } /** * void start() * * Start the applet. */ public void start() { canvas.start(); } /** * void stop() * * Stop the applet. */ public void stop() { canvas.stop(); } /** * void destroy() * * Destroy the applet. */ public void destroy() { canvas.stop(); canvas.destroy(); } private class renderCanvas extends GLAnimJPanel implements KeyListener { /** * renderCanvas(int w, int h) * * Constructor. */ public renderCanvas() { // super(w, h); super(); addKeyListener(this); } /** * void preInit() * * Called just BEFORE the GL-Context is created. */ public void preInit() { stereoView = false; } /** * void init() * * Called just AFTER the GL-Context is created. */ public void init() { gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClearDepth(1.0); gl.glDepthFunc(GL_LESS); gl.glEnable(GL_DEPTH_TEST); gl.glShadeModel(GL_SMOOTH); gl.glMatrixMode(GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(45.0f, (float)getSize().width / (float)getSize().height, 0.1f, 100.0f); gl.glMatrixMode(GL_MODELVIEW); } /** * void destroy() * * Destroy the canvas. */ public void destroy() { cvsDispose(); } /** * void reshape(int width, int height) * * Called after the first paint command. */ public void reshape(int width, int height) { gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(45.0f, (float)getSize().width / (float)getSize().height, 0.1f, 100.0f); gl.glMatrixMode(GL_MODELVIEW); } /** * void display() * * Draw to the canvas. */ public void display() { if (glj.gljMakeCurrent() == false) return; gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); glj.gljSwap(); } /** * void keyTyped(KeyEvent e) * * Invoked when a key has been typed. This event occurs when a key press is followed by a key release. */ public void keyTyped(KeyEvent e) { } /** * void keyPressed(KeyEvent e) * * Invoked when a key has been pressed. */ public void keyPressed(KeyEvent e) { } /** * void keyReleased(KeyEvent e) * * Invoked when a key has been released. */ public void keyReleased(KeyEvent e) { } } private class WindowL extends WindowAdapter { public void windowClosing(WindowEvent we) { destroy(); System.exit(0); } } public static void main(String[] args) { JFrame f = new JFrame("GL4Java Test"); Lesson1 l = new Lesson1(); f.getContentPane().add(l); f.addWindowListener(l.new WindowL()); l.init(); l.start(); // f.add(l); f.setSize(400, 400); f.setVisible(true); } } ________________________________________________________________ GET INTERNET ACCESS FROM JUNO! Juno offers FREE or PREMIUM Internet access for less! Join Juno today! For your FREE software, visit: http://dl.www.juno.com/get/web/. |