Creating a window with LWJGL and JRuby

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):

  1. Install JRuby with RVM
  2. Download LWJGL
  3. Put lwdgj.jar in ./lib/java
  4. Unzip the native extensions (flatten out the directory, ignore solaris) and put them into ./lib/java/native
  5. 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 =, 600)
def self.start

We can then write a little bin file to get this to run:


And there we go, we have a window!

Next, we’ll start to write some OpenGL!

The full source can be dowloaded from GitHub

Leave a Comment


  • JCLL | August 5, 2015

    I’d like to test your jruby script. What is the ./lib you mention ? Thx !

  • Mark Mandel | August 5, 2015

    @JCLL – you can download the full source code at – – you will find the lib folder in there.