Different sides of Ruby development: OpenGL
Table of content
When I take a break from web development, I like to build something unusual in Ruby. Ruby development usually means web services, APIs and other web work, but the language can drive other kinds of software too. This Ruby OpenGL tutorial is one of those experiments: a small 3D scene with axes, cubes, a moving camera, textures and lighting, written with the opengl and gosu gems.
I started by looking for Ruby libraries that work with 3D graphics and found OpenGL for Ruby, a wrapper around the OpenGL API, and wrote a few samples with it. The first steps can be confusing, so let’s go through them one at a time.
To start working with OpenGL for Ruby, the Gemfile lists two gems:
Gemfile.rb:
source "https://rubygems.org" gem "gosu" gem "opengl"
I chose gosu because it handles the window, keyboard input and text output, and it runs raw OpenGL calls inside its gl block, which you will see in every draw method below. The scripts also require glu, the GLU bindings that the opengl gem moved into a separate gem in 2014, so add that gem to the Gemfile as well.
Let’s create something simple!
3D scenes are hard to picture at first, so instead of a cube I started by drawing the axes.
Axes show how coordinates lie on the three-dimensional grid, and a different colour for each line tells you at a glance which one is x, y or z.
I suggest keeping each object in its own class under the objects/ directory. The first one is the axis. The label below says media/axis.rb, but run.rb loads everything from objects/, so save it there:
class Axis attr_reader :x_width, :y_width, :z_width def initialize(x_width, y_width, z_width) @x_width = x_width @y_width = y_width @z_width = z_width end def self.draw(x_width, y_width, z_width) object = new(x_width, y_width, z_width) object.draw end def draw glBegin(GL_LINES) glColor3d(1, 0, 0) glVertex3d(0, 0, 0) glVertex3d(x_width, 0, 0) glColor3d(0, 1, 0) glVertex3d(0, 0, 0) glVertex3d(0, y_width, 0) glColor3d(0, 0, 1) glVertex3d(0, 0, 0) glVertex3d(0, 0, z_width) glEnd end end
All the OpenGL work happens in the draw method. Everything between glBegin and glEnd reads like a Ruby block, and the argument to glBegin is the type of primitive you want to draw. You can find all the types in the official documentation.
Inside this block, you set the lines and their colour. A call to glColor3d sets the colour for every vertex that follows it. The glColor method has many variants that differ only by argument type: glColor3d takes GLdouble, glColor3f takes GLfloat, and so on. glColor3d takes three arguments, the red, green and blue values, and glColor4* adds an alpha value.
To draw a line, you set two points and OpenGL connects them. Each point is a call to glVertex, which takes two to four arguments of different types, depending on the variant you call. Here we pass the x, y and z coordinates of each point. One glBegin…glEnd block can hold as many lines as you need. In my example, the lines start at the origin (x = 0, y = 0, z = 0) and run along each axis up to (x = x_width, y = y_width, z = z_width), measured in pixels.
require 'opengl' require 'glu' require 'gosu' Dir["objects/*"].each {|file| require_relative file } include Gl, Glu class Window < Gosu::Window def initialize super 800, 600 self.caption = "Diatom's OpenGL Tutorial" end def update end def draw gl do glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) Axis.draw(100, 100, 100) end end def button_down(id) exit if id == Gosu::KbEscape end end Window.new.show
glClear resets the buffers to preset values, and then Axis.draw draws our axes.

As you can see, the y axis is missing, because the window border covers it. If you want to see it, start the line at (x = 1) instead of (x = 0).
This raises a question: what if we want to draw objects somewhere other than the top left corner? How do we move to the centre of the axes?
Moving the centre of the axes
To move to the centre of the axes, we use the glTranslate method. It multiplies the current matrix by a translation matrix, which shifts everything by x, y and z. Every object drawn after glTranslate uses the shifted coordinates. To switch between translated and original coordinates, wrap the translated part in glPushMatrix and glPopMatrix: the first saves the current matrix, the second restores it. glTranslate comes in several variants, such as glTranslated(x, y, z), glTranslatef(x, y, z), where x, y and z are the coordinates of a translation vector.
Let’s update our code with this method.
def draw gl do glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glPushMatrix glTranslated(width/2, height/2, 0) Axis.draw(100, 100, 100) glPopMatrix end end
The axes now sit in the centre of the screen. To see how glPushMatrix and glPopMatrix work, let’s draw the previous axes as well.
def draw gl do glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glPushMatrix glTranslated(width/2, height/2, 0) Axis.draw(100, 100, 100) glPopMatrix glEnable(GL_LINE_STIPPLE) glLineStipple(2,0x00FF) Axis.draw(100, 100, 100) glDisable(GL_LINE_STIPPLE) end end
The previous axes are drawn at (0, 0, 0) with stippled lines, and axis.rb and its coordinates stay unchanged.
We still can’t see the z axis on a flat screen. To look at it, we need a viewpoint.
Getting into the real 3D world
First, let’s add another object to the scene: a cube. It makes changes in the viewing angle easy to see.
To draw it, we use GL_QUADS. Every four points define one quad, so a cube needs six quads, or 24 points.
objects/cube.rb:
require 'pry' class Cube attr_reader :x_width, :y_width, :z_width, :mode, :mode_face def initialize(x_width, y_width, z_width, mode_face, mode) @x_width = x_width @y_width = y_width @z_width = z_width @mode = mode @mode_face = mode_face end def self.draw(x_width, y_width, z_width, mode_face = GL_FRONT_AND_BACK, mode = GL_FILL) object = new(x_width, y_width, z_width, mode_face, mode) object.draw end def draw glPolygonMode(mode_face, mode); glBegin(GL_QUADS) #yx glColor3d(1, 0, 0) glVertex3d(0, 0, 0) glVertex3d(x_width, 0, 0) glVertex3d(x_width, y_width, 0) glVertex3d(0, y_width, 0) #yz glColor3d(0, 1, 0) glVertex3d(0, y_width, 0) glVertex3d(0, 0, 0) glVertex3d(0, 0, z_width) glVertex3d(0, y_width, z_width) #zx glColor3d(0, 0, 1) glVertex3d(0, 0, z_width) glVertex3d(0, 0, 0) glVertex3d(x_width, 0, 0) glVertex3d(x_width, 0, z_width) #z -> yx glColor3d(1, 0, 0) glVertex3d(0, 0, z_width) glVertex3d(x_width, 0, z_width) glVertex3d(x_width, y_width, z_width) glVertex3d(0, y_width, z_width) #x -> yz glColor3d(0, 1, 0) glVertex3d(x_width, y_width, 0) glVertex3d(x_width, 0, 0) glVertex3d(x_width, 0, z_width) glVertex3d(x_width, y_width, z_width) #y -> zx glColor3d(0, 0, 1) glVertex3d(0, y_width, z_width) glVertex3d(0, y_width, 0) glVertex3d(x_width, y_width, 0) glVertex3d(x_width, y_width, z_width) glEnd end end
I’ve added two new variables, the arguments for glPolygonMode, which sets the rasterization mode. Its arguments are the face (front, back) and the mode (GL_POINT, GL_LINE, GL_FILL).
Let’s also update the axes and move the code that defines their line types inside the class.
objects/axis.rb:
class Axis attr_reader :x_width, :y_width, :z_width, :stipple def initialize(x_width, y_width, z_width, stipple = false) @x_width = x_width @y_width = y_width @z_width = z_width @stipple = stipple end def self.draw(x_width, y_width, z_width, stipple = false) object = new(x_width, y_width, z_width, stipple) object.draw end def draw if stipple glEnable(GL_LINE_STIPPLE) glLineStipple(2,0x00FF) end glBegin(GL_LINES) ... glEnd glDisable(GL_LINE_STIPPLE) if stipple end end
Now let’s update run.rb to use the new cubes.
def draw gl do glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glPushMatrix glTranslated(width/2, height/2, 0) Axis.draw(100, 100, 100) Cube.draw(50, 50, 50, GL_FRONT_AND_BACK, GL_LINE) glPopMatrix Cube.draw(50, 50, 50, GL_FRONT_AND_BACK, GL_LINE) Axis.draw(100, 100, 100, true) end end
Looks clear, doesn’t it?
To add perspective, we use the gluPerspective method, which sets up a perspective projection. You call it once to define how the scene is rendered, and with gluPerspective in place OpenGL applies the perspective correction while rendering. Its arguments are the field-of-view angle, the aspect ratio, and the near and far clipping distances (z-near and z-far).
So, let’s add perspective to our application.
def draw gl do glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(130, width.to_f/height, 0, 500) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glPushMatrix glTranslated(width/2, height/2, 0) Axis.draw(100, 100, 100) Cube.draw(50, 50, 50, GL_FRONT_AND_BACK, GL_LINE) glPopMatrix Cube.draw(50, 50, 50, GL_FRONT_AND_BACK, GL_LINE) Axis.draw(100, 100, 100, true) end end
The field of view has changed, and now we see only part of the (0, 0, 0) cube and axes. To see what gluPerspective actually changes, let’s add a viewpoint.
To turn the view around the player, OpenGL developers usually build a view matrix, load it and use it to rotate the whole scene. To keep the code simple, we will create a ‘camera’ object that looks at the scene through gluLookAt.
Without gluLookAt, the camera sits at the origin (x = 0, y = 0, z = 0) and looks down the negative z axis. On our screen, that gives the same view direction as gluLookAt(0, 0, 1, 0, 0, 0, 0, 1, 0). So let’s set gluLookAt properly, so we can see the scene.
glMatrixMode(GL_MODELVIEW) glLoadIdentity() <b>gluLookAt(400, 400, 400, 0, 0, 0, 0, 1, 0)</b>
gluLookAt places our camera at (x = 400, y = 400, z = 400) and points it at (x = 0, y = 0, z = 0). The last three arguments define the up vector, which we leave alone for now.
Now let’s play with gluPerspective a bit.
gluPerspective(130, width.to_f/height, 0.001, 225)
What if we want to move the camera and see the other sides of the scene? Gosu’s built-in input handling helps here.
Moving the camera
Every argument of gluLookAt can change. To move the camera, we bind those changes to the keyboard.
I won’t go into the math behind view matrices and real camera rotation, which games handle with formulas for radii and angles. Here the camera moves only along the axes. It’s not the best solution, but it’s the easiest to follow.
Let’s move the gluLookAt call into a new camera object in objects/camera.rb:
class Camera attr_reader :camera_position, :look_at_object_position, :window, :speed def initialize(window) @window = window @camera_position = Vector3.new(400, 400, 400) @look_at_object_position = Vector3.new(0, 0, 0) @speed = 10 end def capture font = Gosu::Font.new(window, Gosu::default_font_name, 20) button_down font.draw("Camera position: #{camera_position.x}:#{camera_position.y}:#{camera_position.z}", 10, 10, 3.0, 1.0, 1.0, 0xffffffff) font.draw("Look at position: #{look_at_object_position.x}:#{look_at_object_position.y}:#{look_at_object_position.z}", 10, 25, 3.0, 1.0, 1.0, 0xffffffff) font.draw("Your speed: #{speed}", 10, 40, 3.0, 1.0, 1.0, 0xffffffff) gluLookAt(camera_position.x, camera_position.y, camera_position.z, look_at_object_position.x, look_at_object_position.y, look_at_object_position.z, 0, 1, 0) end def button_down @camera_position.x += speed if Gosu::button_down?(Gosu::KbRight) && !Gosu::button_down?(Gosu::KB_LEFT_SHIFT) @camera_position.x -= speed if Gosu::button_down?(Gosu::KbLeft) && !Gosu::button_down?(Gosu::KB_LEFT_SHIFT) @camera_position.y += speed if Gosu::button_down?(Gosu::KbUp) && !Gosu::button_down?(Gosu::KB_LEFT_SHIFT) @camera_position.y -= speed if Gosu::button_down?(Gosu::KbDown) && !Gosu::button_down?(Gosu::KB_LEFT_SHIFT) @camera_position.z += speed if Gosu::button_down?(Gosu::KB_NUMPAD_8) && !Gosu::button_down?(Gosu::KB_LEFT_SHIFT) @camera_position.z -= speed if Gosu::button_down?(Gosu::KB_NUMPAD_2) && !Gosu::button_down?(Gosu::KB_LEFT_SHIFT) @look_at_object_position.x += speed if Gosu::button_down?(Gosu::KbRight) && Gosu::button_down?(Gosu::KB_LEFT_SHIFT) @look_at_object_position.x -= speed if Gosu::button_down?(Gosu::KbLeft) && Gosu::button_down?(Gosu::KB_LEFT_SHIFT) @look_at_object_position.y += speed if Gosu::button_down?(Gosu::KbUp) && Gosu::button_down?(Gosu::KB_LEFT_SHIFT) @look_at_object_position.y -= speed if Gosu::button_down?(Gosu::KbDown) && Gosu::button_down?(Gosu::KB_LEFT_SHIFT) @look_at_object_position.z += speed if Gosu::button_down?(Gosu::KB_NUMPAD_8) && Gosu::button_down?(Gosu::KB_LEFT_SHIFT) @look_at_object_position.z -= speed if Gosu::button_down?(Gosu::KB_NUMPAD_2) && Gosu::button_down?(Gosu::KB_LEFT_SHIFT) end end
To make the movement easy to follow, I bound each axis to a key. Here is the scheme for moving the camera:
UP, DOWN - by Y axis LEFT, RIGHT - by X axis NUM8, NUM2 - by Z axis
To move the target point instead, hold Shift and press the same keys.
Gosu’s text output methods show the current coordinates of both points and the camera speed, so the class receives the window object to draw them. For the camera position, I wrote a Vector3 class that holds x, y and z coordinates:
objects/vector3.rb:
Vector3 = Struct.new(:x, :y, :z)
With the camera class ready, let’s use it inside run.rb.
def draw gl do glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(90, width.to_f/height, 0, 500) glMatrixMode(GL_MODELVIEW) glLoadIdentity() @camera.capture glPushMatrix glTranslated(width/2, height/2, 0) Axis.draw(100, 100, 100) Cube.draw(50, 50, 50, GL_FRONT_AND_BACK, GL_LINE) glPopMatrix Cube.draw(50, 50, 50, GL_FRONT_AND_BACK, GL_FILL) Axis.draw(100, 100, 100, true) end end
‘Fly’ around the scene for a bit to see how gluLookAt works.
The keyboard layout can be more practical, and I also want a way to speed the camera up. So let’s rewrite the camera object:
objects/camera.rb
def button_down check_speed case when Gosu::button_down?(Gosu::KbD) @camera_position.x += speed @look_at_object_position.x += speed when Gosu::button_down?(Gosu::KbA) @camera_position.x -= speed @look_at_object_position.x -= speed when Gosu::button_down?(Gosu::KbW) @camera_position.z -= speed @look_at_object_position.z -= speed when Gosu::button_down?(Gosu::KbS) @camera_position.z += speed @look_at_object_position.z += speed when Gosu::button_down?(Gosu::KbUp) @look_at_object_position.y += speed when Gosu::button_down?(Gosu::KbDown) @look_at_object_position.y -= speed when Gosu::button_down?(Gosu::KbRight) @look_at_object_position.x += speed when Gosu::button_down?(Gosu::KbLeft) @look_at_object_position.x -= speed end end def check_speed @speed = 10 @speed = 20 if Gosu::button_down?(Gosu::KB_LEFT_SHIFT) end
Now W and S move the camera along the z axis, A and D move it along the x axis, UP and DOWN move the view target along the y axis, and LEFT and RIGHT move the target along the x axis. Holding Shift doubles the speed.
Let’s play!
Next, let’s attach a cube drawn with lines to our pointer. The cube code needs to receive the current coordinates and build the cube around them.
objects/cube.rb
require 'pry' class Cube attr_reader :position, :x_width, :y_width, :z_width, :mode, :mode_face def initialize(x_width, y_width, z_width, mode_face, mode, x = 0, y = 0, z = 0) @x_width = x_width @y_width = y_width @z_width = z_width @mode = mode @mode_face = mode_face @position = Vector3.new(x, y, z) end def self.draw(x_width, y_width, z_width, mode_face = GL_FRONT_AND_BACK, mode = GL_FILL, x = 0, y = 0, z = 0) object = new(x_width, y_width, z_width, mode_face, mode, x, y, z) object.draw end def draw glPolygonMode(mode_face, mode); glBegin(GL_QUADS) #yx glColor3d(1, 0, 0) glVertex3d(position.x, position.y, position.z) glVertex3d(x_width + position.x, position.y, position.z) glVertex3d(x_width + position.x, y_width + position.y, position.z) glVertex3d(position.x, y_width + position.y, position.z) #yz glColor3d(0, 1, 0) glVertex3d(position.x, y_width + position.y, position.z) glVertex3d(position.x, position.y, position.z) glVertex3d(position.x, position.y, z_width + position.z) glVertex3d(position.x, y_width + position.y, z_width + position.z) #zx glColor3d(0, 0, 1) glVertex3d(position.x, position.y, z_width + position.z) glVertex3d(position.x, position.y, position.z) glVertex3d(x_width + position.x, position.y, position.z) glVertex3d(x_width + position.x, position.y, z_width + position.z) #z -> yx glColor3d(1, 0, 0) glVertex3d(position.x, position.y, z_width + position.z) glVertex3d(x_width + position.x, position.y, z_width + position.z) glVertex3d(x_width + position.x, y_width + position.y, z_width + position.z) glVertex3d(position.x, y_width + position.y, z_width + position.z) #x -> yz glColor3d(0, 1, 0) glVertex3d(x_width + position.x, y_width + position.y, position.z) glVertex3d(x_width + position.x, position.y, position.z) glVertex3d(x_width + position.x, position.y, z_width + position.z) glVertex3d(x_width + position.x, y_width + position.y, z_width + position.z) #y -> zx glColor3d(0, 0, 1) glVertex3d(position.x, y_width + position.y, z_width + position.z) glVertex3d(position.x, y_width + position.y, position.z) glVertex3d(x_width + position.x, y_width + position.y, position.z) glVertex3d(x_width + position.x, y_width + position.y, z_width + position.z) glColor3d(1, 1, 1) #return back primary color glEnd end end
Now we can update the main window’s draw method with this code:
glPushMatrix
glTranslated(width/2, height/2, 0)
Axis.draw(100, 100, 100)
Cube.draw(50, 50, 50, GL_FRONT_AND_BACK, GL_FILL)
Cube.draw(50, 50, 50, GL_FRONT_AND_BACK, GL_LINE, @camera.look_at_object_position.x, @camera.look_at_object_position.y, @camera.look_at_object_position.z)
glPopMatrix
In the end, you should see this view:
Cube creator
What if we want to place some new cubes? Easy!
Let’s change our run.rb code to:
require 'opengl' require 'glu' require 'gosu' Dir["objects/*"].each {|file| require_relative file } include Gl, Glu class Window < Gosu::Window <b>attr_accessor :scene_objects, :translation</b> def initialize super 800, 600 self.caption = "Diatom's OpenGL Tutorial" @camera = Camera.new(self) <b>@scene_objects = [] @translation = Vector3.new(width/2, height/2,0)</b> end def update end def draw gl do glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(90, width.to_f/height, 0, 500) glMatrixMode(GL_MODELVIEW) glLoadIdentity() @camera.capture <b>@scene_objects << Axis.new(100, 100, 100) @scene_objects << Cube.new(50, 50, 50, GL_FRONT_AND_BACK, GL_FILL)</b> glPushMatrix <b>glTranslated(translation.x, translation.y, translation.z) @scene_objects.each do |object| object.draw end</b> glPopMatrix Cube.draw(50, 50, 50, GL_FRONT_AND_BACK, GL_LINE, @camera.look_at_object_position.x, @camera.look_at_object_position.y, @camera.look_at_object_position.z) Cube.draw(50, 50, 50, GL_FRONT_AND_BACK, GL_FILL) Axis.draw(100, 100, 100, true) end end def button_down(id) exit if id == Gosu::KbEscape <b>add_cube if id == Gosu::KbSpace</b> end <b> def add_cube @scene_objects << Cube.new( 50, 50, 50, GL_FRONT_AND_BACK, GL_FILL, @camera.look_at_object_position.x - translation.x, @camera.look_at_object_position.y - translation.y, @camera.look_at_object_position.z - translation.z ) end </b> end Window.new.show
I have highlighted the changes. The translation vector now lives in a Vector3 variable. Every object that gets translated and drawn goes into the @scene_objects array, and a loop places them on the scene.
To add a cube, I create a new cube object and push it into the array. Its coordinates are calculated from the translation vector, so every cube lands in a valid place.
Now let’s add textures. Gosu loads an image from a file, and its gl_tex_info method returns the texture information OpenGL needs. Let’s wrap this in a ‘texture’ class.
class Texture attr_accessor :info def initialize(window, filepath) @image = Gosu::Image.new(window, filepath, {tileable: true, retro: false}) @info = @image.gl_tex_info # gl_tex_info can return nil if the image was too large to fit onto # a single OpenGL texture and was internally split up. end end
Then we update the cube’s draw method with:
texture_info = texture.info glEnable(GL_TEXTURE_2D) # enables two-dimensional texturing to perform glBindTexture(GL_TEXTURE_2D, texture_info.tex_name) # bing named texture to a target glPixelStorei(GL_UNPACK_ALIGNMENT,1) draw_textured_cube glDisable(GL_TEXTURE_2D)
Inside draw_textured_cube, each vertex gets a glTexCoord2d call that says which point of the texture belongs to it. The texture’s bottom left corner is (0, 0) and its top right corner is (1, 1), so we stretch it between the edges of each cube face. Here is the code for one side:
glTexCoord2d(0,0); glVertex3d(position.x, position.y, position.z) glTexCoord2d(1,0); glVertex3d(x_width + position.x, position.y, position.z) glTexCoord2d(1,1); glVertex3d(x_width + position.x, y_width + position.y, position.z) glTexCoord2d(0,1); glVertex3d(position.x, y_width + position.y, position.z)
By adding some lights with
glEnable(GL_LIGHTING) glLightfv(GL_LIGHT0, GL_AMBIENT, [0.5, 0.5, 0.5, 1]) glLightfv(GL_LIGHT0, GL_DIFFUSE, [1, 1, 1, 1]) glLightfv(GL_LIGHT0, GL_POSITION, [1, 1, 1,1]) glLightfv(GL_LIGHT1, GL_AMBIENT, [0.5, 0.5, 0.5, 1]) glLightfv(GL_LIGHT1, GL_DIFFUSE, [1, 1, 1, 1]) glLightfv(GL_LIGHT1, GL_POSITION, [100, 100, 100,1]) glEnable(GL_LIGHT0)
depth testing, so nearer faces hide the ones behind them in the depth buffer,
glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); glDepthFunc(GL_LEQUAL);
and textures with
glEnable(GL_TEXTURE_2D) # enables two-dimensional texturing to perform glBindTexture(GL_TEXTURE_2D, texture_info.tex_name) # bing named texture to a target glPixelStorei(GL_UNPACK_ALIGNMENT,1)
we get a textured scene with real lighting.
With some more work, you can let the player switch the material of the blocks being placed, and add other features.
Video of the finished scene: YouTube
All the code is in our repository on GitHub, which is now archived and read-only.
What Has Changed Since 2017
The listings above are the original 2017 code, kept as a record of how the scene was built. If you plan to run or extend them today, check these points first.
The opengl gem has had no release since 0.10.0 in June 2017, and the glu and glut gems it split off in 2014 were last released in 2017 too. For Ruby OpenGL work on a current setup, look at opengl-bindings2, updated in January 2026. It covers OpenGL up to 4.6 and OpenGL ES up to 3.2 through Ruby’s Fiddle, includes GLFW, GLUT and GLU bindings, and the older opengl-bindings gem now asks its users to migrate to it. Its API is namespaced (GL.Enable(GL::DEPTH_TEST) instead of glEnable(GL_DEPTH_TEST)), so the code here would need porting.
Gosu is still in development: in June 2026 its main branch moved from SDL2 to SDL3. The latest stable gem is 1.4.6 from May 2023, and version 2.0 is in pre-release. Gosu 1.4.6 still runs raw OpenGL code inside the gl block and accepts the old constant names used above, such as Gosu::KbEscape, and the window argument to Gosu::Image.new, but marks both as deprecated.
The bigger change is in OpenGL itself. glBegin, glEnd, the matrix stack (glPushMatrix, glTranslate) and fixed-function lighting were deprecated in OpenGL 3.0 and removed from the 3.1 core, so this code needs a legacy or compatibility context. In modern OpenGL you build the matrices yourself and pass them to shaders. OpenGL 4.6, released on 31 July 2017, is still the latest version. Apple deprecated OpenGL in macOS 10.14 and points developers to Metal. For new low-level graphics code, Khronos maintains Vulkan, a cross-platform standard that also reaches macOS and iOS through MoltenVK. In the browser, WebGPU (a W3C Candidate Recommendation Draft as of September 2026) gives pages GPU rendering and compute.
OpenGL has bindings for most languages, so what you learn here carries over to C++, Python or JavaScript through WebGL. Ruby is just as flexible outside web apps: if you have an unusual idea, we can build it with Ruby!













