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
Danielle Smith
February 10, 2016
Programming
31
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RubyGL
Ruby + OpenGL
Danielle Smith
February 10, 2016
More Decks by Danielle Smith
See All by Danielle Smith
Ruby Ruby
daninithepanini
0
150
A Brief History of Ruby
daninithepanini
0
49
Static Type Inferencing ... in Ruby?
daninithepanini
0
27
Off the Rails
daninithepanini
0
44
Action Game
daninithepanini
0
41
YeSQL
daninithepanini
0
29
Game Dev in Ruby
daninithepanini
0
43
Euler vs Hamilton
daninithepanini
0
47
Other Decks in Programming
See All in Programming
はてなアカウント基盤 State of the Union
cockscomb
0
660
The NotImplementedError Problem in Ruby
koic
1
920
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
210
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
400
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.5k
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
13
6.2k
Inside Stream API
skrb
1
770
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
180
New "Type" system on PicoRuby
pocke
1
1k
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
260
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
800
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
170
Featured
See All Featured
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
950
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.3k
The Pragmatic Product Professional
lauravandoore
37
7.3k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
RailsConf 2023
tenderlove
30
1.5k
Designing Experiences People Love
moore
143
24k
30 Presentation Tips
portentint
PRO
1
330
Navigating Team Friction
lara
192
16k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
480
The Art of Programming - Codeland 2020
erikaheidi
57
14k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
44k
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]