Hey guys,
I've just finished downloading and installing LWJGL and am attempting to add it to my existing game framework (most of the game's logic is done, it just needs rendering now).
Here is the basic idea of my code (all run in an Applet!), with all the irrelevant garbage removed:
public class xMain extends Applet implements Runnable {
protected xCanvas m_jCanvas = null;
public void start() {
try {
this.m_jCanvas = new xCanvas();
System.out.println("canvas exists");
} catch (Exception e) {
e.printStackTrace();
}
}
public void run() {
while (true) {
this.repaint();
}
}
@Override
public void paint(Graphics g) {
System.out.println("main is painting");
this.m_jCanvas.repaint();
}
}
public class xCanvas extends AWTGLCanvas {
public xCanvas() throws Exception {
super();
}
@Override
public void initGL() {
System.out.println("canvas initialized");
}
@Override
public void paintGL() {
System.out.println("canvas painting");
}
}
Here is the program's output (no errors):
run:
canvas exists
main is painting
main is painting
main is painting
main is painting
(etc.)
However, as you can see, it never prints "canvas initialized" or "canvas painting". If I explicitly call m_jCanvas.initGL(), I get a null pointer error if I call any G11.* functions:
run:
canvas initialized
java.lang.NullPointerException
at org.lwjgl.opengl.GL11.glShadeModel(GL11.java:2323)
at gfx.xCanvas.initGL(xCanvas.java:14)
I'm working in NetBeans 6.9 (AppletViewer), using LWJGL 2.5, and the libraries are loaded as they are compiling (and Display.create() works--but I want to paint in the applet rather than create a new window).
Other things I have tried:
- add(this.m_jCanvas);
- Implementing Runnable in xCanvas
- Using .update(g), .update(this.m_jCanvas.getGraphics()), .repaint(), .paint(g)
Any suggestions? All help is appreciated.