Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RubyGL
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Danielle Smith
February 10, 2016
Programming
0
28
RubyGL
Ruby + OpenGL
Danielle Smith
February 10, 2016
Tweet
Share
More Decks by Danielle Smith
See All by Danielle Smith
Ruby Ruby
daninithepanini
0
140
A Brief History of Ruby
daninithepanini
0
40
Static Type Inferencing ... in Ruby?
daninithepanini
0
23
Off the Rails
daninithepanini
0
30
Action Game
daninithepanini
0
37
YeSQL
daninithepanini
0
25
Game Dev in Ruby
daninithepanini
0
38
Euler vs Hamilton
daninithepanini
0
44
Other Decks in Programming
See All in Programming
Architectural Extensions
denyspoltorak
0
270
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
220
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
680
AI巻き込み型コードレビューのススメ
nealle
0
100
SourceGeneratorのススメ
htkym
0
190
Apache Iceberg V3 and migration to V3
tomtanaka
0
150
dchart: charts from deck markup
ajstarks
3
990
Data-Centric Kaggle
isax1015
2
760
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
20
6.7k
AIエージェントのキホンから学ぶ「エージェンティックコーディング」実践入門
masahiro_nishimi
3
280
MUSUBIXとは
nahisaho
0
130
CSC307 Lecture 04
javiergs
PRO
0
650
Featured
See All Featured
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
110
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.7k
New Earth Scene 8
popppiees
1
1.5k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Bash Introduction
62gerente
615
210k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
1
1.3k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
A better future with KSS
kneath
240
18k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
430
How to Ace a Technical Interview
jacobian
281
24k
Transcript
RubyGL Ruby + OpenGL
What is OpenGL?
Talks to your Graphics Processor
Universal API for all hardware
Compare with Web Dev Graphics Processor OpenGL ? ? Network
Card HTTP Rack Rails
Why OpenGL?
Cross Platform
Runs on anything with a Graphics Processor
No license required
Used by millions
Why OpenGL + Ruby?
OpenGL is a C library
C isn’t fun :(
Ruby is fun :)
How OpenGL + Ruby?
$ gem install opengl-bindings
Call OpenGL functions from Ruby
Problem?
We inherit all the problems we had writing OpenGL in
C
Function order issues
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(...)
Whack naming conventions
“Mesh” or “3D Object” == “Vertex Array Object (VAO)”
Pointers… :(
buffer = ' '*8 glGenBuffers(1, buffer) buffer = buffer.unpack('L')[0]
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)
No real exception handling
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 ...
“impossible” debugging
Something went wrong ¯\_(ツ)_/¯
Something went horribly wrong ¯\_(ツ)_/¯
OpenGL in Ruby is just as hard as C
:(
Has anyone solved this?
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 ◦ ...
So… not really.
Solution!
Let’s solve this!
Let’s fix function order issues
Extract method! def draw(buffer) glBindBuffer(buffer) glDrawElements(...) end
Let’s fix whack naming conventions
Abstract OpenGL as a “proper” OOP library class Mesh def
initialize @buffer = glCreateBuffer() end def draw glBindBuffer(@buffer) glDrawElements(...) end end
Let’s fix Pointers… :(
def create_buffer buffer = ' '*8 glGenBuffers(1, buffer) buffer.unpack('L')[0] end
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
Let’s fix no real exception handling
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
Let’s fix “impossible” debugging
¯\_(ツ)_/¯
Mittsu
Mittsu (it’s a Japanese word for the number Three)
The “Rack” of Graphics Programming
Compare with Web Dev Graphics Processor OpenGL Mittsu ? Network
Card HTTP Rack Rails
Based off THREE.js (So it inherits pretty much the same
API structure)
Still a bit rough around the edges (It inherited most
of the crappy code structure, too)
Demo!
The Future
Performance
If Mittsu is the “Rack”, What is the “Rails”?
Support all the environments!
One API to rule them all!
Imagine: OSX/iOS + Metal + Rubymotion Android + OpenGL ES
+ Rubymotion JVM + LWJGL/JOGL + JRuby Windows + DirectX? Vulkan? (next-gen OpenGL)
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
One more thing...
THAAAAANKS!!!
Tweet: @jellym4nn Collaborate: github.com/jellymann Contact:
[email protected]