LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Craumix on August 09, 2015, 18:43:05

Title: Contoller integration
Post by: Craumix on August 09, 2015, 18:43:05
Hello i'm new at lwjgl and i have a xbox contoller and want to use it.
I've searched for the org.lwjgl.input package in the build 3.0.0b build 9 but it doesn't seems to be there...
So how can I use Controllers?
Title: Re: Contoller integration
Post by: Cornix on August 09, 2015, 18:56:09
LWJGL uses GLFW, so look here:
http://www.glfw.org/docs/latest/group__joysticks.html
Title: Re: Contoller integration
Post by: Craumix on August 09, 2015, 20:15:23
I tried:
System.out.println(GLFW.glfwGetJoystickName(GLFW.GLFW_JOYSTICK_1));
But I only get:
Exception in thread "main" java.lang.NullPointerException
at org.lwjgl.system.MemoryUtil.memDecodeUTF8(MemoryUtil.java:1153)
at org.lwjgl.system.MemoryUtil.memDecodeUTF8(MemoryUtil.java:1140)
at org.lwjgl.glfw.GLFW.glfwGetJoystickName(GLFW.java:2426)
at game.Game.main(Game.java:13)
Title: Re: Contoller integration
Post by: abcdef on August 09, 2015, 21:31:57
Did you initialise GLFW first? You don't need a window created but you need to initialise GLFW for that command to work

Take from getting started page


// Initialize GLFW. Most GLFW functions will not work before doing this.
        if ( glfwInit() != GL11.GL_TRUE )
            throw new IllegalStateException("Unable to initialize GLFW");


Edit :

But it would be nice that  if null came back a "no" would be returned instead (to say not present).
Title: Re: Contoller integration
Post by: spasi on August 10, 2015, 13:02:10
Quote from: abcdef on August 09, 2015, 21:31:57But it would be nice that  if null came back a "no" would be returned instead (to say not present).

Indeed, I will fix this in the next build. Thanks!
Title: Re: Contoller integration
Post by: spasi on August 10, 2015, 21:06:47
Fixed in build 3.0.0b #14.