How to get LWJGL working?

I have tried to run org.xith3d.test.benchmark.MultiCubeBenchmark with LWJGL.

So I changed the line in the main method of this class in the following way:


-   Canvas3DWrapper canvas = Canvas3DWrapper.createStandalone(Xith3DTest.DEFAULT_RESOLUTION, "MultiCubeBenchmark");
+  Canvas3DWrapper canvas = Canvas3DWrapper.createStandalone(OpenGLLayer.LWJGL, Xith3DTest.DEFAULT_RESOLUTION, ColorDepth.B32, "MultiCubeBenchmark");

But I get the following error:


java.lang.NullPointerException
	at org.lwjgl.opengl.GL11.glGetInteger(GL11.java:1799)
	at com.xith3d.render.lwjgl.CanvasPeerImpl.renderStart(CanvasPeerImpl.java:285)
	at com.xith3d.render.lwjgl.CanvasPeerImpl.display(CanvasPeerImpl.java:868)
	at com.xith3d.render.lwjgl.CanvasPeerImpl.render(CanvasPeerImpl.java:1035)
	at com.xith3d.scenegraph.View.renderOnce(View.java:614)
	at org.xith3d.render.multipass.MultiPassView.renderOnce(MultiPassView.java:249)
	at org.xith3d.render.multipass.MultiPassView.renderOnce(MultiPassView.java:392)
	at org.xith3d.render.base.ExtXith3DEnvironment.render(ExtXith3DEnvironment.java:225)
	at org.xith3d.render.loop.RenderLoop.invokeRendering(RenderLoop.java:428)
	at org.xith3d.render.loop.RenderLoop.loopIteration(RenderLoop.java:444)
	at org.xith3d.render.loop.ExtRenderLoop.loopIteration(ExtRenderLoop.java:187)
	at org.xith3d.test.benchmark.BenchmarkBase.loopIteration(BenchmarkBase.java:102)
	at org.xith3d.test.benchmark.MultiCubeBenchmark.loopIteration(MultiCubeBenchmark.java:73)
	at org.xith3d.render.loop.RenderLoop.run(RenderLoop.java:553)
	at java.lang.Thread.run(Unknown Source)
Exception in thread "Thread-4" java.lang.Error: java.lang.NullPointerException
	at com.xith3d.render.lwjgl.CanvasPeerImpl.display(CanvasPeerImpl.java:987)
	at com.xith3d.render.lwjgl.CanvasPeerImpl.render(CanvasPeerImpl.java:1035)
	at com.xith3d.scenegraph.View.renderOnce(View.java:614)
	at org.xith3d.render.multipass.MultiPassView.renderOnce(MultiPassView.java:249)
	at org.xith3d.render.multipass.MultiPassView.renderOnce(MultiPassView.java:392)
	at org.xith3d.render.base.ExtXith3DEnvironment.render(ExtXith3DEnvironment.java:225)
	at org.xith3d.render.loop.RenderLoop.invokeRendering(RenderLoop.java:428)
	at org.xith3d.render.loop.RenderLoop.loopIteration(RenderLoop.java:444)
	at org.xith3d.render.loop.ExtRenderLoop.loopIteration(ExtRenderLoop.java:187)
	at org.xith3d.test.benchmark.BenchmarkBase.loopIteration(BenchmarkBase.java:102)
	at org.xith3d.test.benchmark.MultiCubeBenchmark.loopIteration(MultiCubeBenchmark.java:73)
	at org.xith3d.render.loop.RenderLoop.run(RenderLoop.java:553)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
	at org.lwjgl.opengl.GL11.glGetInteger(GL11.java:1799)
	at com.xith3d.render.lwjgl.CanvasPeerImpl.renderStart(CanvasPeerImpl.java:285)
	at com.xith3d.render.lwjgl.CanvasPeerImpl.display(CanvasPeerImpl.java:868)
	... 12 more

What am I doing wrong? Of course I believe the error is anywhere in the Canvas3DWrapper. But I don’t know where. I always thought, you could easily switch the CanvasPeerImpl and everything is fine, isn’t it?

the only way a glGetInteger can throw an NPE is if the context isn’t valid anymore…

try Display.makeCurrent(); somewhere…

DP

Thanks, I tried this directly after the makeCanvas call. But unfortunately this didn’t change anything. :frowning:

Adding the makeCurrent() directly before the view.renderOnce() call with a boolean flag to do it only once, the following error occurrs:


Exception in thread "Thread-3" java.lang.IllegalStateException: From thread Thread[Thread-3,5,main]: Thread[main,5,] already has the context current
	at org.lwjgl.opengl.Context.checkAccess(Context.java:169)
	at org.lwjgl.opengl.Context.makeCurrent(Context.java:176)
	at org.lwjgl.opengl.Display.makeCurrent(Display.java:576)
	at org.xith3d.render.base.ExtXith3DEnvironment.render(ExtXith3DEnvironment.java:241)
	at org.xith3d.render.loop.RenderLoop.invokeRendering(RenderLoop.java:433)
	at org.xith3d.render.loop.RenderLoop.loopIteration(RenderLoop.java:449)
	at org.xith3d.render.loop.ExtRenderLoop.loopIteration(ExtRenderLoop.java:187)
	at org.xith3d.test.benchmark.BenchmarkBase.loopIteration(BenchmarkBase.java:102)
	at org.xith3d.test.benchmark.MultiCubeBenchmark.loopIteration(MultiCubeBenchmark.java:73)
	at org.xith3d.render.loop.RenderLoop.run(RenderLoop.java:558)
	at java.lang.Thread.run(Unknown Source)

Could someone perhaps give me a little LWJGL test program which does not much more than creating a working Canvas3D (in xith)? Or point me to a link where I can find an example?

I think there are some more lines you have to call in difference to using JOGL (or JSR-231) additionally to a different RenderPeerImpl, aren’t there?

EDIT: I use the lwjgl version shipped with xith3d cvs checkout.

Seems to me that your trying to render from a different thread that created the Display (and as a result, the context); notice the difference in thread names. To solve this problem, you need to do Display.releaseContext() on the thread that made the display and then Display.makeCurrent() on the thread you want to render in…

DP

It seems like this is the problem. Thanks. When I create the CanvasPeer in the RenderThread, my code doesn’t crash. But that’s not practicable. One should be able to create the Canvas outside the RenderThread. But since the org.lwjgl.opengl.Context class is NOT public in the 0.98 release (which is used in xith), you cannot call the releaseContext method. Hence you cannot call makeCurrent().

Seems like we need to use a newer lwjgl version. This version is not usable for us. Whom of you does actually use lwjgl in his xith game? Are you using the current version of xith/lwjgl? Are you creating the Canvas inside the RenderThread?

Upgrade to 1.0b and do what I said in my last post. After creating your Canvas, call “Display.releaseContext();”

Then, on the rendering thread, call “Display.makeCurrent();” once and be on your way…

(PS, upgrading to 1.0b shouldn’t need any code changes, since the API hasn’t changed; yay for API stability)

DP

Yes this worked. Thank you very, very much for your help.

Qudus