www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: AGP on April 16, 2009, 08:20:45 pm

Title: lwjgl Joystick
Post by: AGP on April 16, 2009, 08:20:45 pm
I have two programs. One uses an AWT window and initializes the FrameBuffer like this:
Code: [Select]
buffer = new FrameBuffer(width, height, SAMPLINGMODE_NORMAL);
buffer.enableRenderer(IRenderer.MODE_OPENGL);
Then (after World.renderScene(buffer) and World.draw(buffer)) calls buffer.display(Graphics). The other, like this:
Code: [Select]
buffer = new FrameBuffer(width, height, SAMPLINGMODE_HARDWARE_ONLY);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL);
then makes only buffer.displayGLOnly() calls. Oddly, the first program initializes and uses the lwjgl joystick succesfully whereas the second one can't get past controllers.create()! Why oh why?
Title: Re: lwjgl Joystick
Post by: EgonOlsen on April 16, 2009, 08:28:13 pm
What happens? Does it crash or is there a deadlock or what?

BTW:
Code: [Select]
buffer.enableRenderer(IRenderer.MODE_OPENGL);
is actually wrong. It will give you a software renderer in OpenGL-mode but that's more by accident than intentionally. Correct is:

Code: [Select]
buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE);
Title: Re: lwjgl Joystick
Post by: AGP on April 16, 2009, 08:30:07 pm
I know, I realized it as I typed it here. But that's the code that runs the joystick. The other one just throws an LWJGLException (which I catch), so nothing happens but I can't access the joystick.
Title: Re: lwjgl Joystick
Post by: EgonOlsen on April 16, 2009, 08:37:47 pm
Can you post the actual exception?
Title: Re: lwjgl Joystick
Post by: AGP on April 16, 2009, 09:50:00 pm
I figured it out. Part of it is the fact that although it compiles with just a reference to lwjgl.jar, to run you have to reference jinput.jar. Plus, Vista x64 is giving me a headache. I can't wait for EVERYTHING to be 64-bit already.

Here's another joystick-related question: I wrote years ago a Java 2D game which only used the keyboard. Yesterday I decided to add the lwjgl joystick to it, so instead of drawing into the awt frame I added the AWTGLCanvas to the frame and drew on the canvas. This time I initialize the controllers just fine and even get a Controller instance. But when I poll the joystick for input, its value are always -1. I realize this question belongs in the lwjgl boards but there are a lot more people here.
Title: Re: lwjgl Joystick
Post by: EgonOlsen on April 16, 2009, 09:55:12 pm
You may try to query the stick in the startPainting()-method of an IPaintListener, albeit i don't think that OpenGL and joysticks are related, but you never know.
Or maybe there is a kind of update() or poll() method for the controller, that will be called automatically when using a normal Display but that will be omitted when using the AWTGLCanvas? I'm just guessing here, but LWJGL tends to bind all kind of input polling to the Display.
Title: Re: lwjgl Joystick
Post by: EgonOlsen on April 16, 2009, 10:09:11 pm
You are using an AWTGLCanvas (i.e. obtained from FrameBuffer.enableGLCanvasRenderer()) and are calling Display.setParent(canvas) too? Interesting...i would think that the setParent() hasn't any purpose here or does it?

Anyway, that's quite off topic. Sadly, i've never used any joystick related stuff. So it does work with the normal, native GL display but doesn't work with the AWTGL-based one?
Title: Re: lwjgl Joystick
Post by: AGP on April 16, 2009, 10:14:44 pm
Actually, in this case I'm referencing lwjgl directly (no jPCT). But I must be thinking more clearly today than I was yesterday because I solved it. Thanks for your help, pal.