|
I use GLJPanel and I write below code but I have below error But I do not take any error GLcanvas. I think I take error when I call getContext() method. How can I solve this problem
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.media.opengl.GLJPanel.getContext(GLJPanel.java:787) at FisrtJoglPackage.SceneRenderer.<init>(JOGLDemo5.java:221) .............. ..............
public class JOGLDemo5 extends JFrame implements ChangeListener { final static int WIDTH = 100; final static int HEIGHT = 100;
final static int FPS = 30; private SceneRenderer sr; FPSAnimator animator;
public JOGLDemo5 () { super ("JOGLDemo #5");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GLCapabilities caps=new GLCapabilities(); caps.setAlphaBits(0); sr = new SceneRenderer (caps); final Animator animator = new Animator(sr); sr.setPreferredSize (new Dimension (WIDTH, HEIGHT)); this.add(sr); initGui(); pack (); setVisible (true); animator.start(); }
public static void main (String [] args) { Runnable r = new Runnable () { public void run () { new JOGLDemo5 (); } }; EventQueue.invokeLater (r); }
class SceneRenderer extends GLJPanel implements GLEventListener,MouseListener,MouseMotionListener { public SceneRenderer ( GLCapabilities caps) { super(caps); GLContext context= this.getContext(); context.getGL(); addGLEventListener (this); }
public void init (GLAutoDrawable drawable) { GL gl = drawable.getGL (); glc=drawable.getGL(); gl.glEnable (GL.GL_DEPTH_TEST); gl.glShadeModel(GL.GL_SMOOTH); gl.glClearColor(0, 0, 0, 0); }
public void display (GLAutoDrawable drawable) { GL gl = drawable.getGL ();
//Draw Something
}
public void reshape (GLAutoDrawable drawable, int x, int y, int width, int height) {
}
|