[ruby-opengl-devel] opinions on rubygl

John Gabriele jmg3000 at gmail.com
Thu Aug 31 13:13:25 EDT 2006


There's been some messages bouncing around off-list about rubygl
http://rubyforge.org/projects/rubygl/ , and since they might be of
interest to anyone else following this list, I thought they really
belonged in their own thread here. So here's a few discussion points
regarding rubygl:

1. rubygl is like Yoshi's original ruby-opengl in that it's written
mostly by-hand (possibly (hopefully?) assisted by-script). Thus, the
rubygl code is very neat and tidy. SWIG, OTOH, generates an awful lot
of boilerplate and helper-code to do its job. I'm guessing that SWIG
is essential for larger projects, but a hindrance for very small ones.
My hunch is that wrapping OpenGL and GLUT lands somewhere near the
middle but leaning toward the smaller side.

Also, SWIG seems most useful when the library you're wrapping changes
often. Admittedly, OpenGL and GLUT do not change very often.


2. Naming conventions. Contrary to how the current ruby-opengl does
things (which I'd done most of the pushing for):

| require 'GL'
| include GL
| glFooBar( GL_FOO_BAR )

code that uses rubygl looks more like this:

| require 'rubygl'
| include Gl, Glu, Glut
| foo_bar( :foo_bar )

The reasoning for using our syntax is to make it as similar to the C
API as possible to ease the transition for folks who already know the
C API. Also, it's to make it easier to port your Ruby OpenGL code to C
if it were to become necessary.

That said, the rubygl naming is more customary with how things are
usually done in the Ruby world, and admittedly does look rather
spiffy. ;)


3. Callbacks are handled a bit more simply in rubygl. The rubygl code
(I think) looks like:

| display_func do |w, h|
|     viewport ...
|     matrix_mode :projection
|     #...
|     matrix_mode :modelview
|     load_identity
| end

compared to how it's done in ruby-opengl:

| reshape = lambda do |w, h|
|     glViewport( ... )
|     glMatrixMode( GL_PROJECTION )
|     # etc.
|     glMatrixMode( GL_MODELVIEW )
|     glLoadIdentity
| end
|
| glutReshapeFunc( reshape )

I haven't yet looked closely at how the C code to enable this syntax
differs from what ruby-opengl has. And, actually, since I'm so new at
working with extension modules, I don't yet know a whole lot about
what I'm looking at.

Discussion welcome.

---John


More information about the ruby-opengl-devel mailing list