F:\java\projects\GLAnimJPanelTest>javac GLAnimJPanelTest.java
F:\java\projects\GLAnimJPanelTest>java GLAnimJPanelTest
set fps := 20.0 -> 50 [ms/frame]
Exception in thread "main" java.lang.NullPointerException
at GLtest.display(GLAnimJPanelTest.java:83)
at GLtest.(GLAnimJPanelTest.java:33)
at GLAnimJPanelTest.main(GLAnimJPanelTest.java:17)
2 questions:
1) why is this happening?
2) how do I fix it?
here is my code:
// awt packages
import java.awt.event.*;
import java.awt.Component;
//GL4Java classes
import gl4java.GLContext;
import gl4java.swing.GLAnimJPanel;
import gl4java.drawable.*;
// swing packages
import javax.swing.*;
public class GLAnimJPanelTest {
public static void main(String[] args) {
JFrame f = new JFrame("GLAnimJPanelTest");
GLtest p = new GLtest();
f.getContentPane().add(p);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p.run();
f.pack();
f.show();
}
}
class GLtest extends GLAnimJPanel implements KeyListener, MouseListener {
/*----------[]--------------------------------------------------------------------------------*/
GLtest() {
super(true);
init();
display();
}
/*----------[]--------------------------------------------------------------------------------*/
public void init() {
// I don''t want stereo view
stereoView = false;
// Enable Texture Mapping
gl.glEnable(GL_TEXTURE_2D);
// This Will Clear The Background Color To Black
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// Enables Clearing Of The Depth Buffer
gl.glClearDepth(1.0);
// The Type Of Depth Test To Do
gl.glDepthFunc(GL_LESS);
// Enables Depth Testing
gl.glEnable(GL_DEPTH_TEST);
// Enables Smooth Color Shading
gl.glShadeModel(GL_SMOOTH);
// Select The Projection Matrix
gl.glMatrixMode(GL_PROJECTION);
// Reset The Projection Matrix
gl.glLoadIdentity();
// Calculate The Aspect Ratio Of The Window
glu.gluPerspective(45.0f, (float)getSize().width / (float)getSize().height, 0.1f, 100.0f);
// Select The Modelview Matrix
gl.glMatrixMode(GL_MODELVIEW);
}
/*----------[]--------------------------------------------------------------------------------*/
public void reshape(int width, int height) {
// Reset The Current Viewport And Perspective Transformation
gl.glViewport(0, 0, width, height);
// Select The Projection Matrix
gl.glMatrixMode(GL_PROJECTION);
// Reset The Projection Matrix
gl.glLoadIdentity();
// Calculate The Aspect Ratio Of The Window
glu.gluPerspective(45.0f, (float)getSize().width / (float)getSize().height, 0.1f, 100.0f);
// Select The Modelview Matrix
gl.glMatrixMode(GL_MODELVIEW);
}
/*----------[]--------------------------------------------------------------------------------*/
public void doCleanup() {
cvsDispose();
}
/*----------[]--------------------------------------------------------------------------------*/
public void display() {
if (glj.gljMakeCurrent() == false) return;
// glj.gljMakeCurrent();
gl.glTranslatef(0, 0, -8);
gl.glBegin(GL_TRIANGLES);
gl.glColor3f(0f,1f,1f);
gl.glVertex3f(0f, 2f, 0f);
gl.glColor3f(1f,0f,1f);
gl.glVertex3f(-2f, -1f, 0f);
gl.glColor3f(1f,1f,0f);
gl.glVertex3f(2f, -1f, 0f);
gl.glEnd();
//Swap buffers
glj.gljSwap();
glj.gljFree(true);
}
/*----------[]--------------------------------------------------------------------------------*/
public void keyTyped(KeyEvent e) {
//We are not handling any keyboard events yet
}
public void keyPressed(KeyEvent e) {
//We are not handling any keyboard events yet
}
public void keyReleased(KeyEvent e) {
//We are not handling any keyboard events yet
}
public void mouseExited( MouseEvent evt ) { }
public void mousePressed( MouseEvent evt ) {
Component comp = evt.getComponent();
if( comp.equals(this ) ) {
requestFocus();
}
}
public void mouseReleased( MouseEvent evt ) { }
public void mouseClicked( MouseEvent evt ) {
Component comp = evt.getComponent();
if( comp.equals(this ) ) {
requestFocus();
}
}
/*----------[]--------------------------------------------------------------------------------*/
}