This is the most basic of steps before getting anything done with LWJGL and JRuby, so I figured I would document it to help people with the initial hurdles.
Before doing anything with LWJGL and JRuby, you need to set things up correctly so that LWJGL can find its native extensions. The easiest way I found to do this was the following (tested on Linux):
- Install JRuby with RVM
- Download LWJGL
- Put lwdgj.jar in ./lib/java
- Unzip the native extensions (flatten out the directory, ignore solaris) and put them into ./lib/java/native
- Create a
.rvmrc
in the root of the dir with the following code in it:
export JRUBY_OPTS="-J-Djava.library.path=lib/java/native"
This sets the JRUBY_OPTS
environment variable, which tells JRuby to append these arguments to all JRuby operations. This obviously doesn’t work for deployment, but during development it makes thing very handy.
Now to write some Ruby code to get a window up and running!
First we need to require java, and the lwjgl jar file:
require 'java'
require 'java/lwjgl.jar'
Drawing the window is now very straightforward:
java_import org.lwjgl.opengl.Display
java_import org.lwjgl.opengl.DisplayMode
#
# Just a basic display using lwjgl
class OpenGL::BasicDisplay
# initialise
def initialize
Display.display_mode = DisplayMode.new(800, 600)
Display.create
while(!Display.is_close_requested)
Display.update()
end
Display.destroy
end
def self.start
OpenGL::BasicDisplay.new
end
end
We can then write a little bin file to get this to run:
OpenGL::BasicDisplay.start
And there we go, we have a window!
Next, we’ll start to write some OpenGL!
The full source can be dowloaded from GitHub
Comments
I’d like to test your jruby script. What is the ./lib you mention ? Thx !
@JCLL – you can download the full source code at – https://github.com/markmandel/jruby-lwjgl – you will find the lib folder in there.