Czipperz
Czipperz

Reputation: 3336

LWJGL Controllers in IntelliJ

Every time I try to build a basic example program for using LWJGL controllers, it crashes. Here's the code:

package com.czipperz.blogspot.tests.controllers;


import org.lwjgl.LWJGLException;
import org.lwjgl.input.Controller;
import org.lwjgl.input.Controllers;

/**
 * Created by Chris on 10/23/2014.
 */
public class Main {
//left joystick x and y
private float x, y,
//right joystick x and y.  Like the commas?
              rx, ry;
//This Controller object MUST BE org.lwjgl.input.Controller NOT net.java.games.input.Controller
private Controller c;
private boolean start;

public static final int BUTTON_A = 1, BUTTON_B = 2, BUTTON_X = 3, BUTTON_Y = 4,
                        BUTTON_LEFT_BUMPER = 5, BUTTON_RIGHT_BUMPER = 6, BUTTON_SELECT = 7, BUTTON_START = 8,
                        //When you PRESS the joysticks (click)
                        BUTTON_LEFT_JOYSTICK = 9, BUTTON_RIGHT_JOYSTICK = 10;

public static void main(String[] args) {
    new Main();
}

public Main() {
    //Says, find controllers and store them in the Controllers class to JInput. Dont worry bout it.
    try {
        Controllers.create();
    } catch (LWJGLException e) {
        e.printStackTrace();
    }
    // Gets you a shiny "new" controller instance.
    // Think of index like you would think of an array.
    c = Controllers.getController(0);

    //Sets "deadband"
    float dead = .06f;
    c.setXAxisDeadZone(dead);
    c.setYAxisDeadZone(dead);
    c.setRXAxisDeadZone(dead);
    c.setRYAxisDeadZone(dead);

    //Using the controller requires you to call the poll() function to receive new data.
    c.poll();
    x = c.getXAxisValue();
    y = c.getYAxisValue();
    rx = c.getRXAxisValue();
    ry = c.getRYAxisDeadZone();
    //NOTE: getZAxisValue(), getRZAxisValue(), getZAxisDeadZone(), getRZAxisDeadZone() DO NOT WORK

    //DPAD = POV
    float povx = c.getPovX();
    float povy = c.getPovY();

    boolean lbumper = c.isButtonPressed(BUTTON_LEFT_BUMPER);
}
}

The problem is that every time I build, this is the log: (Sorry I just can't hit space that many times)

"C:\Program Files\Java\jdk1.8.0_25\bin\java" -Didea.launcher.port=7533 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains IntelliJ IDEA Community Edition 13.1.5\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_25\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\zipfs.jar;C:\Users\Chris\workspace\Controllers\out\production\Controllers;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lzma.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\jinput.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl_test.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl_util.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl-debug.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\asm-debug-all.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl_util_applet.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\AppleJavaExtensions.jar;C:\Program Files (x86)\JetBrains IntelliJ IDEA Community Edition 13.1.5\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.czipperz.blogspot.tests.controllers.Main
WARNING: Found unknown Windows version: Windows 8.1
Attempting to use default windows plug-in.
Loading: net.java.games.input.DirectAndRawInputEnvironmentPlugin
java.lang.UnsatisfiedLinkError: no jinput-dx8_64 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1119)
at net.java.games.input.DirectInputEnvironmentPlugin$1.run(DirectInputEnvironmentPlugin.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at          net.java.games.input.DirectInputEnvironmentPlugin.loadLibrary(DirectInputEnvironmentPlugin.java:67)
at net.java.games.input.DirectInputEnvironmentPlugin.<clinit>(DirectInputEnvironmentPlugin.java:109)
at net.java.games.input.DirectAndRawInputEnvironmentPlugin.<init>(DirectAndRawInputEnvironmentPlugin.java:45)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:438)
at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:157)
at org.lwjgl.input.Controllers.create(Controllers.java:71)
at com.czipperz.blogspot.tests.controllers.Main.<init>(Main.java:32)
at com.czipperz.blogspot.tests.controllers.Main.main(Main.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
java.lang.UnsatisfiedLinkError: no jinput-raw_64 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1119)
at net.java.games.input.RawInputEnvironmentPlugin$1.run(RawInputEnvironmentPlugin.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at net.java.games.input.RawInputEnvironmentPlugin.loadLibrary(RawInputEnvironmentPlugin.java:67)
at net.java.games.input.RawInputEnvironmentPlugin.<clinit>(RawInputEnvironmentPlugin.java:109)
at net.java.games.input.DirectAndRawInputEnvironmentPlugin.<init>    (DirectAndRawInputEnvironmentPlugin.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:438)
at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:157)
at org.lwjgl.input.Controllers.create(Controllers.java:71)
at com.czipperz.blogspot.tests.controllers.Main.<init>(Main.java:32)
at com.czipperz.blogspot.tests.controllers.Main.main(Main.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at org.lwjgl.input.Controllers.getController(Controllers.java:116)
at com.czipperz.blogspot.tests.controllers.Main.<init>(Main.java:38)
at com.czipperz.blogspot.tests.controllers.Main.main(Main.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
net.java.games.input.DirectAndRawInputEnvironmentPlugin is not supported

Process finished with exit code 1

Upvotes: 0

Views: 926

Answers (2)

A.Najafi
A.Najafi

Reputation: 691

In LWJGL there is a "native/" folder containing the respective native libraries for each platform/OS. Just choose your platform and set java.library.path to that directory. This is your problem.

First Step: Create a folder and rename it to LWGJL_New then in that folder create two other folders and rename the first on libs and the second one natives. Now go to the LWGJL library that you have downloaded. Copy the jar files to LWGJL_New/libs. Then go to the LWGJL library that you have downloaded, in it, there is a folder containing respective native libraries for each platform/OS. Choose one of them that you need and copy it to LWGJL_New/natives.

Second step: Go to the module settings of your project(F4) then click library.Click add sign(+).Click on java. Now find the LWGJL_New folder and in it click on the jar folder and click ok. Then Click on Apply and ok.

Third step: Now if you run your project you will occur that problem, So go to the Edit Configuration part menu

Then in VM options write this:

-Djava.library.path="***"

Instead of star signs write the address of the native folder that we have just created.

For example ->

 D:\LWGJL_New\natives\windwos
 D:\LWGJL_New\natives\linux

Then click on OK. Then run your project.

Upvotes: 0

xyz
xyz

Reputation: 11

I know this thread is old, but for people who are searching for the solution. The answer is, you have to include the native libs to your project. For the use of jinput.jar you have to include following libs:

  • jinput-dx8.dll
  • jinput-dx8_64.dll
  • jinput-raw.dll
  • jinput-raw_64.dll

You can download the natives here DOWNLOAD.

  1. You will get a jar-file. Unzip the file with winrar to get the dll-files.
  2. Now go to project and open the context menu with a click on the right mouse button -> Build Path -> Configure Build Path -> Choose the Libraries tab -> Click on the little arrow next to the jinput.jar to expand the view -> Make a double click with the left mouse button on Native library location -> Choose the directory of the dll-files.
  3. Confirm the dialogs and try to run your program again.

Upvotes: 1

Related Questions