Ruby, SDL and OpenGL
NOTE: This is an old post which I am merely republishing. The earlier version was lost due to a RAID failure on my former web host’s server.
I had a bit of trouble tracking down decent documentation for Ruby/SDL and Ruby/OpenGL, so I thought I’d put together some sample code in case anybody is interested in it.
require 'sdl'
require 'opengl'
# initialize SDL and OpenGL
SDL.init(SDL::INIT_VIDEO | SDL::INIT_AUDIO | SDL::INIT_TIMER)
screen = SDL.set_video_mode(800, 600, 16, SDL::HWSURFACE | SDL::OPENGL)
GL.ClearColor(0.0, 0.0, 1.0)
GL.ClearDepth(1.0)
finished = false
while not finished
# pull events from the input queue
while event = SDL::Event2.poll
# watch for quit events
if event.kind_of?(SDL::Event2::Quit)
finished = true
break
end
end
# clear the screen
GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT)
# TODO: rendering code goes here!
# display the back buffer
SDL.GL_swap_buffers
end
# terminate SDL
SDL.quit
Obviously, the convention is underscored lower case method names for Ruby/SDL (although camelCase aliases are provided too), while Ruby/OpenGL’s API uses UpperCamelCase and breaks Ruby convention by using a capital letter for the first character.
Update: Here’s documentation for Ruby/SDL .