Author Topic: lwjgl Joystick  (Read 3689 times)

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
lwjgl Joystick
« 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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: lwjgl Joystick
« Reply #1 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);

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: lwjgl Joystick
« Reply #2 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: lwjgl Joystick
« Reply #3 on: April 16, 2009, 08:37:47 pm »
Can you post the actual exception?

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: lwjgl Joystick
« Reply #4 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: lwjgl Joystick
« Reply #5 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: lwjgl Joystick
« Reply #6 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?

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: lwjgl Joystick
« Reply #7 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.