Ruby binding for GLFW

G

Glenn M. Lewis

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
 
T

Tobias Nurmiranta

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top