Hello Guest

Totally striking out with AWTGLCanvas

  • 2 Replies
  • 5619 Views
*

Zack

Totally striking out with AWTGLCanvas
« 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:
Code: [Select]
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();
}
}
Code: [Select]
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):
Code: [Select]
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:
Code: [Select]
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.
« Last Edit: July 22, 2010, 22:39:59 by Zack »

*

Offline kappa

  • *****
  • 1319
Re: Totally striking out with AWTGLCanvas
« Reply #1 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

« Last Edit: July 22, 2010, 22:45:44 by javalwjgl »

*

Zack

Re: Totally striking out with AWTGLCanvas
« Reply #2 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!