OpenGL 3D gears demo for Ruby
by Arto Bendiken other posts by this author
Apr 30 2005 11:09PM messages near this date
Re: Performance of SyncEnumerator
|
Re: OpenGL 3D gears demo for Ruby
Hi there,
I'm a recent convert from Python, PHP et al., and aside from more
serious web-related development with Rails, have been playing a bit
with Yoshi's OpenGL/GLUT bindings. I was interested to see how
ruby-opengl performance would compare with C/C++, so I wrote a Ruby
version of the (in)famous spinning 3D gear wheels demo program, which
is often used as a simple benchmark for OpenGL.
(Kudos to Yoshi for the OpenGL bindings: translating from the original
C code was straightforward and only took an hour or so to finish.)
The results were a bit surprising, in a good way. On my Linux computer
with ATI Radeon 9700, the compiled version of the original gears.c
gives an average 1271 FPS, whereas the gears.rb version achieves an
average of 1203 FPS. (Both programs were run for a couple of minutes
and results averaged.) That's only a 6% gap in performance.
Granted this is a fairly simple OpenGL app, but it's certainly easy to
imagine how productive programmers of open-source games, simulations
etc. could be writing Ruby instead of C/C++ as is the norm.
I've attached the Ruby file gears.rb. It only requires the ruby-opengl
extension to run. The code was translated from rev 1.8 of the
GLUT-based gears.c (not the same as glxgears!) included in the Mesa 3D
software package, keeping the structure close to the original, but
wrapping it in a Ruby class. I also added some simple code to do mouse
rotation. If anyone wishes to compare performance with the original
version, it can downloaded from:
http://cvs.freedesktop.org/mesa/Mesa/progs/demos/gears.c
Arto Bendiken
Attachments:
gears.rb
unknown1
Thread:
Arto Bendiken
Ilmari Heikkinen
|