How to get LWJGL working with Leiningen & Clojure.
I've noticed that I get several hits per week on this project. So, I've decided to update this and write a "How To" for you to create your own LWJGL clojar natives release.
Now with LWJGL3 goodness!
The following setup echoes how I made the library work for my shadertone project. I haven't updated that to LWJGL3, yet, though.
I have verified this works for LWJGL 3.0.0 build 90 on Mac/Linux/Windows.
The official LWJGL package is not setup properly for Clojure. It mixes the 32 and 64-bit libraries and the current Leiningen workaround for this doesn't work. What follows are the instructions on creating your own clojars package of LWJGL. IMO, it is easier to make your own package than to work around the issues that the official package presents.
You don't have to create your own LWJGL library. You can just use mine if you'd like. But, this is how I created it for myself. I did this on a Mac. Linux will be similar. You'll have to translate this for Windows yourself.
Goto https://www.lwjgl.org/download and get the lwjgl.zip file you want. Instructions below assume LWJGL 3.0.0 build 90 (see build.txt file) which is the file that was downloaded via the "Release" button in June, 2016.
unzip lwjgl.zip
mkdir sandbox
cd sandbox
(As of 3.0.0 there are no longer 32-bit binaries provided for linux.)
mkdir -p native/macosx/x86_64
mkdir -p native/linux/x86_64
mkdir -p native/windows/x86
mkdir -p native/windows/x86_64
cp ../native/OpenAL.dll native/windows/x86_64
cp ../native/OpenAL32.dll native/windows/x86
cp ../native/glfw.dll native/windows/x86_64
cp ../native/glfw32.dll native/windows/x86
cp ../native/jemalloc.dll native/windows/x86_64
cp ../native/jemalloc32.dll native/windows/x86
cp ../native/libglfw.dylib native/macosx/x86_64
cp ../native/libglfw.so native/linux/x86_64
cp ../native/libjemalloc.dylib native/macosx/x86_64
cp ../native/libjemalloc.so native/linux/x86_64
cp ../native/liblwjgl.dylib native/macosx/x86_64
cp ../native/liblwjgl.so native/linux/x86_64
cp ../native/libopenal.dylib native/macosx/x86_64
cp ../native/libopenal.so native/linux/x86_64
cp ../native/lwjgl.dll native/windows/x86_64
cp ../native/lwjgl32.dll native/windows/x86
cp -r ../doc .
jar xvf ../jar/lwjgl.jar
jar -cMf lwjgl-3.0.0.jar META-INF doc org native
Note, I've skipped including the src.
Change this as-needed for your own purposes.
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>hello_lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<version>3.0.0</version>
<name>lwjgl</name>
<description>Packaging of LWJGL3 for Clojure</description>
<url>http://github.com/roger_allen/hello_lwjgl</url>
</project>
mvn install:install-file -Dfile=lwjgl-3.0.0.jar -DpomFile=pom.xml
edit project.clj to use [hello_lwjgl/lwjgl "3.0.0"]
lein clean
lein -o deps
lein -o run alpha
Add authentication info to settings.xml (typically in your ~/.m2 directory):
<settings>
<servers>
<server>
<id>clojars</id>
<username>username</username>
<password>password</password>
</server>
</servers>
</settings>
Then you can deploy (from the sandbox dir) with
mvn deploy:deploy-file -Dfile=lwjgl-3.0.0.jar -DpomFile=pom.xml -DrepositoryId=clojars -Durl=https://clojars.org/repo
> rm -rf ~/.m2/repository/hello_lwjgl/lwjgl
> lein deps
Retrieving hello_lwjgl/lwjgl/3.0.0/lwjgl-3.0.0.pom from clojars
Retrieving hello_lwjgl/lwjgl/3.0.0/lwjgl-3.0.0.jar from clojars
> lein run alpha
That should do it. Now you have LWJGL from Clojure. Enjoy! If you have feedback on this, please file an issue and let me know.
p.s. One thing I could improve here is adding the LWJGL license properly. If you can suggest a proper way to package that, file an issue.
If you want to create your own application using Clojure & LWJGL, here's what I did:
> lein new app hello_lwjgl
> cd hello_lwjglSee project.clj and the source code for more info. Hopefully it is easy to follow.
All of these are very basic examples.
A spinning triangle that uses OpenGL 1.1
A spinning triangle that uses OpenGL 3.2
A fullscreen spinning triangle that uses OpenGL 1.1 and you can move with a keyboard. The triangle also rotates to follow the mouse.
To run these examples, just add the name to the lein run commandline. E.g. to run the 'alpha' test:
> lein run alphaBecause of interations between the GLFW and AWT window system and Mac OS X, using the REPL on Mac OS X is a bit different than on PC/Linux. On PC/Linux, I think you can just use lein repl as you would normally. But, on Mac, we need to start the nREPL server ourselves in a separate thread. See Issue #6 for details and thanks to @antoinevg for his efforts in figuring this out.
For Mac OS X, we have added the Emacs cider-nrepl package in order to get a REPL working. I'm not sure about other external tools, so for now cider-nrepl is the way to get a REPL on the Mac. To start this, add cider after the name of the example. E.g. lein alpha cider will create a cider-nrepl server and report this on startup. Something like this:
> lein run alpha cider
Hello, Lightweight Java Game Library! V 3.0.0b SNAPSHOT
Run example Alpha
Starting Cider Nrepl Server Port 7888
OpenGL version: 2.1 NVIDIA-10.4.2 310.41.35f01
In emacs, use M-x cider-connect and use port 7888 to connect. A repl pane shoudl open up. Now, you can adjust the code live, for example, adjust the angle of the triangle.
user> (in-ns 'hello-lwjgl.alpha)
#namespace[hello-lwjgl.alpha]
hello-lwjgl.alpha> (swap! globals assoc :angle 0.0)
Please note that you may need to adjust the cider-nrepl package version to match your local install. It changes often.
First create the 'uberjar'
> lein uberjar
...
Created .../hello_lwjgl/target/hello_lwjgl-0.2.0-SNAPSHOT-standalone.jarThen you can run it with just a little extra help on the commandline. Here are instructions for Mac. Extrapolate for Windows/Linux.
> java -Djava.library.path=native/macosx/x86_64 -jar hello_lwjgl-0.2.0-SNAPSHOT-standalone.jar- found this helpful example: https://github.com/honeytree/clojure-lwjgl
- found this discussion: https://groups.google.com/forum/#!msg/leiningen/MAFbNqDYT78/Ub2scaa4RCoJ
- See this issue for some background. technomancy/leiningen#898
- If you get an error similar to this, update to Java 8: java.lang.UnsupportedClassVersionError: org/lwjgl/opengl/GL : Unsupported major.minor version 52.0
Copyright © 2013-2016 Roger Allen.
Distributed under the Eclipse Public License, the same as Clojure.