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
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
29
Action Game
daninithepanini
0
37
YeSQL
daninithepanini
0
25
Game Dev in Ruby
daninithepanini
0
37
Euler vs Hamilton
daninithepanini
0
44
Other Decks in Programming
See All in Programming
はじめてのカスタムエージェント【GitHub Copilot Agent Mode編】
satoshi256kbyte
0
140
從冷知識到漏洞,你不懂的 Web,駭客懂 - Huli @ WebConf Taiwan 2025
aszx87410
2
3.3k
Flutter On-device AI로 완성하는 오프라인 앱, 박제창 @DevFest INCHEON 2025
itsmedreamwalker
1
170
tparseでgo testの出力を見やすくする
utgwkk
2
340
GISエンジニアから見たLINKSデータ
nokonoko1203
0
190
AtCoder Conference 2025
shindannin
0
870
AI Agent Dojo #4: watsonx Orchestrate ADK体験
oniak3ibm
PRO
0
120
AIの誤りが許されない業務システムにおいて“信頼されるAI” を目指す / building-trusted-ai-systems
yuya4
6
4.1k
Python札幌 LT資料
t3tra
7
1.1k
「コードは上から下へ読むのが一番」と思った時に、思い出してほしい話
panda728
PRO
39
26k
Basic Architectures
denyspoltorak
0
150
Pythonではじめるオープンデータ分析〜書籍の紹介と書籍で紹介しきれなかった事例の紹介〜
welliving
3
710
Featured
See All Featured
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.7k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
42
From π to Pie charts
rasagy
0
100
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
0
84
Mobile First: as difficult as doing things right
swwweet
225
10k
Reality Check: Gamification 10 Years Later
codingconduct
0
2k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
130
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
38
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
2.8k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
0
270
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
530
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
130
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]