Can't get LWJGL to run using IDEA and SBT

梦想的初衷 提交于 2019-12-01 04:48:30

You can include LWJGL (with natives) by simply adding the following snippet to your build.sbt:

libraryDependencies ++= {
  val version = "3.1.6"
  val os = "windows" // TODO: Change to "linux" or "macos" if necessary

  Seq(
    "lwjgl",
    "lwjgl-glfw",
    "lwjgl-opengl"
    // TODO: Add more modules here
  ).flatMap {
    module => {
      Seq(
        "org.lwjgl" % module % version,
        "org.lwjgl" % module % version classifier s"natives-$os"
      )
    }
  }
}

The classifier function sadly is very undocumented so it took me some time to find this out.

I know this is quite a bit old, but I thought this might help others who come across this problem. What I did myself was download the jar file from the site, extract the natives from the jar and add them to my resources directory. As for lwjgl I added it to my sbt project as you have. During runtime, I extracted the natives from the jar and loaded the native libraries using

System.load("<native-library-name>")

then set the natives directory for lwjgl using

System.setProperty("org.lwjgl.librarypath", <natives-path>)

Also, as for extracting the natives from your jar file during runtime, you could do something like this

val source = Channels.newChannel(
NativesLoader.getClass.getClassLoader.getResourceAsStream("<native>"))

val fileOut = new File(<desination directory>, "<native path in jar>")
val dest = new FileOutputStream(fileOut)
dest.getChannel.transferFrom(source, 0, Long.MaxValue)
source.close()
dest.close()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!