Ruby binding for GLFW


(Glenn Lewis) #1

Someone over in the news://news.digitalmars.com/D newsgroup
just announced a D binding for GLFW (http://glfw.sourceforge.net/), which
is a very cool framework for OpenGL… check out the included examples!

Has anyone created a binding of GLFW for Ruby?  I couldn't find it

on RAA. It would probably be a snap with SWIG. If not, I’ll try it out.

						-- Glenn

(Tobias Nurmiranta) #2

Hi,

If you haven’t seen it already, you can use GLUT which has at least a
subset of the functionality. As a newbie to Ruby, I must say I like the
feeling in the language ^_^. For example, it was very easy to make a
webcam viewer using OpenGL and Video4Linux.
, Tobias

require “V4l” # http://www.freepan.org/all/by-dist/ruby-v4l/
require “opengl” # http://www2.giganet.net/~yoshi/
require “glut” # included in the opengl module.

width = 320
height = 240
vid = V4l.new
vid.open("/dev/video")
vid.set_size(width, height)

display = Proc.new {
GL.RasterPos(0, 0)
GL.DrawPixels(width, height, GL::RGB, GL::UNSIGNED_BYTE, vid.capture)
GLUT.SwapBuffers
GLUT.PostRedisplay
}

reshape = Proc.new {|w, h|
GL.Viewport(0, 0, w, h)
GL.MatrixMode(GL::PROJECTION)
GL.LoadIdentity
GLU.Ortho2D(0.0, w, 0.0, h)
GL.MatrixMode(GL::MODELVIEW)
GL.LoadIdentity
}

keyboard = Proc.new {|key, x, y| exit(0) if key == 27 } #escape

GLUT.Init
GLUT.InitDisplayMode(GLUT::DOUBLE | GLUT::RGB)
GLUT.InitWindowSize(320, 240)
GLUT.InitWindowPosition(100, 100)
GLUT.CreateWindow($0)
GL.ClearColor(0.0, 0.0, 0.0, 0.0)
GL.ShadeModel(GL::FLAT)
GL.PixelStorei(GL::UNPACK_ALIGNMENT, 1)
GLUT.DisplayFunc(display)
GLUT.ReshapeFunc(reshape)
GLUT.KeyboardFunc(keyboard)
GLUT.MainLoop

···

On Wed, 3 Mar 2004, Glenn M. Lewis wrote:

Has anyone created a binding of GLFW for Ruby? I couldn’t find it
on RAA. It would probably be a snap with SWIG. If not, I’ll try it out.