Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RubyGL

 RubyGL

Ruby + OpenGL

Avatar for Danielle Smith

Danielle Smith

February 10, 2016
Tweet

More Decks by Danielle Smith

Other Decks in Programming

Transcript

  1. Have to remember to bind objects before you use them

    glBindBuffer(some_buffer) glBufferData(some_data_to_put_in_the_buffer) # ... glBindBuffer(some_buffer) glDrawElements(...)
  2. glBindBuffer(some_buffer) array = [1,2,3,4,...] ptr = Fiddle.Pointer.new( array.pack('L' * array.length

    * BYTES_PER_INT) ) glBufferData(ptr, 0, array.length * BYTES_PER_INT)
  3. glSomething(...) raise “error!” unless glGetError.zero? glSomething(...) raise “error!” unless glGetError.zero?

    glSomething(...) raise “error!” unless glGetError.zero? glSomething(...) raise “error!” unless glGetError.zero? # etc ...
  4. :(

  5. Ruby Graphics Libraries ◦ Rubygame: 2D only, latest commit in

    2011 ◦ jemini: 2D only, latest commit in 2013 ◦ ray: limited 3D support, latest commit in 2013 ◦ shoes: GUI, 2D only, JRuby only ◦ gosu: 2D only ◦ ruby-opengl: bindings only ◦ ...
  6. Abstract OpenGL as a “proper” OOP library class Mesh def

    initialize @buffer = glCreateBuffer() end def draw glBindBuffer(@buffer) glDrawElements(...) end end
  7. def bind_buffer_data(buffer, data) glBindBuffer(some_buffer) ptr = FFI.Pointer.new( array.pack('L' * data.length

    * BYTES_PER_INT) ) glBufferData(ptr, 0, data.length * BYTES_PER_INT) end
  8. module OpenGLDebug def method_missing(sym) retval = OpenGL.send(sym, args) # do

    thing puts sym, args, retval # debug error = glGetError raise error unless error.zero? # check error retval end end
  9. Still a bit rough around the edges (It inherited most

    of the crappy code structure, too)
  10. Imagine: OSX/iOS + Metal + Rubymotion Android + OpenGL ES

    + Rubymotion JVM + LWJGL/JOGL + JRuby Windows + DirectX? Vulkan? (next-gen OpenGL)
  11. Contribute! https://github.com/jellymann/mittsu https://rubygems.org/gems/mittsu I need help with: • Testing! •

    Refactoring! • Find Bugs! • Write documentation e.g. Getting Started Guide