OpenGL (opengl3)

OpenGL wrapper library for Ruby

  • Pure Ruby, no C/C++/Java extension included (thanks to ffi gem)
  • OpenGL 2.1 ~ 4.2
  • automatic error checking each function call
  • Ruby-style wrapper (not complete)
  • Works on OS X 10.8 and Linux
  • Inspired by PyOpenGL

Notice

Since the project is not complete, many functions are still C-style. But don't worry, the gem makes use of ffi gem to import functions, and therefore you can use ffi objects like FFI::MemoryPointer to work with C-style OpenGL entrypoints.

Ruby-Style OpenGL APIs

Please take a look at lib/opengl/wrapper/**/*.rb to see if entrypoints are wrapped.

  • glGetString() -> String
  • glGenObjects(count) -> Array of Integer
  • glDeleteObjects(Array of Integer) -> nil
  • glGetValuefv(*args, count) -> Array of Float
  • glGetValueiv(*args, count) -> Array of Integer
  • glGetValueuiv(*args, count) -> Array of Integer
  • glShaderSource(shader, Array of String) -> nil
  • glGetShaderInfoLog(shader) / glGetProgramInfoLog(program) -> String
  • More will be added

block-style glMapBuffer / glMapBufferRange:

glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY) do |ptr|
  ptr.put_array_of_GLfloat(offset_in_bytes, [ 1.0, 2.0, 3.0 ])
end

And helper functions

  • glGetVersion() -> Array of Integer
  • glGetShadingLanguageVersion() -> Array of Integer
  • glGetAvailableExtensions() -> Array of String
  • glIsShaderCompiled?(shader) -> boolean
  • glIsProgramLinked?(program) -> boolean
  • More will be added

Installation

Add this line to your application's Gemfile:

gem 'opengl3', :require => 'opengl'

And then execute:

$ bundle

Or install it yourself as:

$ gem install opengl3

Usage

require 'opengl'
class App
  include OpenGL::Constants

  def initialize
    # ... (window created)
    self.extend OpenGL::GL.entrypoints
    # OK, you can use OpenGL now
  end

end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request