Yet another OpenGL wrapper for Ruby (and wrapper code generator).
Yet another OpenGL wrapper for Ruby (and wrapper code generator).
...and wrapper code generator.
Attention : Version 2 is now available
Though I will continue making this version 1.6 series of opengl-bindings available, please consider migrating to opengl-bindings2.
In version 2, all OpenGL APIs are defined as public methods under module GL, so we don't have to include OpenGL and scatter OpenGL APIs under other modules any more:
# opengl-bindings
require 'opengl'
include OpenGL
# ...
glEnable(GL_DEPTH_TEST)↓
# opengl-bindings2
require 'opengl'
# ...
GL.Enable(GL::DEPTH_TEST)All redundant nil checks done on every API calls are removed in version 2:
# opengl-bindings1
module OpenGL
#...
def self.get_command( sym )
if GL_FUNCTIONS_MAP[sym] == nil
bind_command( sym )
end
return GL_FUNCTIONS_MAP[sym]
end
#...
def glEnable(_cap_)
f = OpenGL::get_command(:glEnable) # Every API call caused redundant nil check here
f.call(_cap_)
end↓
# opengl-bindings2
module GL
#...
def self.Enable(_cap_)
GL_FUNCTIONS_MAP[:glEnable].call(_cap_) # Hashmap is built on initialization so there's no need to do nil check at every API call
endUses Fiddle (One of the Ruby libraries that wraps libffi)
Uses Khronos XML API registry ( https://github.com/KhronosGroup/OpenGL-Registry )
Via RubyGems ( https://rubygems.org/gems/opengl-bindings2 ):
$ gem install opengl-bindings2Or grab all library codes (`lib/*.rb') and use them by adding as one of the load paths like:
$ ruby -I ./lib your_app.rbSee sample/simple.rb or sample/simple_glut.rb.
To get more samples and generator scripts, please visit: https://github.com/vaiorabbit/ruby-opengl
'opengl.rb' includes these scripts:
'opengl_es.rb' is almost the same with 'opengl.rb', except for including 'opengl_es_command.rb' and 'opengl_es_enum.rb'.
'opengl_ext.rb' includes these scripts:
'opengl_es_ext.rb' is almost the same with 'opengl_ext.rb', except for including 'opengl_es_ext_command.rb' and 'opengl_es_ext_enum.rb'.
'glfw.rb'
'glut.rb'
'glu.rb'
'generator/gl.xml'
'generator/Rakefile'
'sample/simple.rb', 'sample/simple_glut.rb'
'sample/data', 'sample/util'
Use GLFW or GLUT for creating windows and OpenGL rendering contexts.
GLFW
freeglut
Ruby
Windows 11 Pro (Version 25H2, OS Build 26200.7462)
> ruby report_env.rb
Version : 4.5.0 NVIDIA 591.44
Vendor : NVIDIA Corporation
Renderer : NVIDIA GeForce RTX 4080 Laptop GPU/PCIe/SSE2
Shader : 4.50 NVIDIA
macOS 26.2 / Mac mini (M1 2020)
$ ruby report_env.rb
Version : 4.1 Metal - 90.5
Vendor : Apple
Renderer : Apple M1
Shader : 4.10
Arch Linux kernel 4.1.2-2-ARCH, Nvidia Driver, x86_64
OpenGL 4.5.0
$ ruby report_env.rb
Version: 4.5.0 NVIDIA 352.21Arch Linux kernel 4.1.4-1-ARCH, Nouveau Driver, x86_64
OpenGL 3.0
$ ruby report_env.rb
Version: 3.0 Mesa 10.6.3Older versions
Ruby
Windows 11 Pro (Version 24H2, OS Build 26100.2605)
Version : 4.5.0 NVIDIA 560.94
Vendor : NVIDIA Corporation
Renderer : NVIDIA GeForce RTX 4080 Laptop GPU/PCIe/SSE2
Shader : 4.50 NVIDIA
Windows 10 Home, 64-bit (Version 1909, OS Build 18363.778)
OpenGL 4.5
> ruby report_env.rb
Version : 4.5.0 NVIDIA 436.30
Vendor : NVIDIA Corporation
Renderer : GeForce RTX 2060 SUPER/PCIe/SSE2
Shader : 4.50 NVIDIAWindows 10 Home, 64-bit (Version 1511, OS Build 10586.164)
OpenGL 4.5
> ruby report_env.rb
Version: 4.5.0 NVIDIA 364.72Windows 7 Home Premium, 64-bit (Service Pack 1)
OpenGL 4.3
> ruby report_env.rb
4.3.0Windows 7 Home Premium, 64-bit (Service Pack 1)
OpenGL 4.3
> ruby report_env.rb
4.3.0Mac OS X 10.8.4, 64-bit
OpenGL 2.1
$ ruby report_env.rb
2.1 NVIDIA-8.12.47 310.40.00.05f01Mac OS X 10.10.5, 64-bit
OpenGL 4.1
$ ruby report_env.rb
Version: 4.1 INTEL-10.6.33Mac OS X 10.15.3, 64-bit
OpenGL 4.1
$ ruby report_env.rb
Version : 4.1 INTEL-14.4.23
Vendor : Intel Inc.
Renderer : Intel Iris OpenGL Engine
Shader : 4.10macOS 12.5.1, 64-bit
OpenGL 4.1
$ ruby report_env.rb
Version : 4.1 Metal - 76.3
Vendor : Apple
Renderer : Apple M1
Shader : 4.10macOS 15.2 / Mac mini (M1 2020)
$ ruby report_env.rb
Version : 4.1 Metal - 89.3
Vendor : Apple
Renderer : Apple M1
Shader : 4.10No Ruby-Style handy interfaces are available (like one in the ruby-opengl2 ( http://ruby-opengl.rubyforge.org/ ))
(Original C API)
GLuint tex_names_buf[2];
glGenTextures( 2, tex_names_buf );
GLuint tex_name = tex_names_buf[0];
(This library)
tex_names_buf = ' ' * 8 # String instance that is enough to catch texture names (integer).
glGenTextures( 2, tex_names_buf )
tex_name = tex_names_buf.unpack('L2')[0]
(ruby-opengl2)
tex_name = glGenTextures( 2 )[0]Projects using opengl-bindings
No open issues yet, or sync has not completed.