LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Zack on July 22, 2010, 22:35:37

Title: Totally striking out with AWTGLCanvas
Post by: Zack on July 22, 2010, 22:35:37
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:

Any suggestions? All help is appreciated.
Title: Re: Totally striking out with AWTGLCanvas
Post by: kappa on July 22, 2010, 22:42:17
maybe you'd have better luck going the Display.setParent() route instead of using AWTGLCanvas. Display.setParent() is also slightly faster then AWTGLCanvas and more compatible.

Example found here (http://java-game-lib.svn.sourceforge.net/viewvc/java-game-lib/trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java?revision=3385&view=markup)

Title: Re: Totally striking out with AWTGLCanvas
Post by: Zack on July 22, 2010, 23:03:40
Ahh, huzzah! I was looking for a Display in Applet tutorial all day, but didn't find one. That's perfect though, and it's working like a charm. Thanks!