GLApp

multi-colored triangles in a circle

I had to get this out of my system so that I could get back to focusing on exams. You don't understand; this has nothing to do with any of the finals or projects I have coming up in the next two days. Oh god, why did this bug have to bite today.

It's a Ruby mini-framework for OpenGL/GLUT applications. It's a raw, unconfigurable, toy, and it's small enough to understand in one sitting so that you can get over that initial hump of starting a GLUT application and just start coding already.

You could say it's Processing-inspired, but that would be an insult to Processing. I don't wrap anything good (yet), so you still need to know how to use the drawing calls wrapped by ruby-opengl, and deal with popping pushed matrices, and all the good stuff you can learn at NeHe's OpenGL tutorial pages, like everyone else on the Internet.

Why do this? Handling OpenGL initialization is already enough to almost make 3D fun. You get to jump right in and start drawing!

Getting GLApp

I've published the source code in a GLApp GitHub repository, which isn't meant to be scary. If you know how to use git, then great, but if not, just click the "Download" link at the top of the project page there.

Or click here: download GLApp from GitHub.

Using GLApp

It's really easy; all you need are the ruby-opengl gem and the gl_app.rb file. Check out triangles.rb in the examples/ directory of the download for a fairly simple example (the one I used to generate the graphic at the top of this page). Here is an excerpt from the README:

It's simple:

  1) require "gl_app"
  2) include GLApp
  3) override as many of the callbacks as you need:
     - setup
     - draw
     - update(seconds)
     - special_keyboard(key, modifiers)
     - mouse_click(button, state, x, y)
     - mouse_active_motion(x, y)
     - mouse_passive_motion(x, y)
     - keyboard(key, modifiers)
  4) call go_windowed(width, height)

Look at the scripts in the examples/ directory.
In fact, here's one:

  require "gl_app"
  include GLApp

  def draw
    glTranslate 0, 0, -5
    glutSolidCube 2
  end

  go_windowed 800, 600