# OpenGL support

**URL:** <https://rubytalk.org/t/opengl-support/61201>\
**Category:** ruby-talk\
**Created:** [20 December 2010 20:12 UTC](https://rubytalk.org/t/opengl-support/61201 "2010-12-20T20:12:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chananya\_Freiman](https://avatars.discourse-cdn.com/v4/letter/c/ad7895/32.png) [@Chananya\_Freiman](https://rubytalk.org/u/Chananya_Freiman)\
**Post date:** [20 December 2010 20:12 UTC](https://rubytalk.org/t/opengl-support/61201/1 "2010-12-20T20:12:02Z")

</div>

Will there ever be updated bindings to OpenGL?  
I can't understand how there's a language without working bindings to  
the biggest open source graphics API out there.

ruby-opengl only seems to work on Ruby 1.8, and ruby/glew is from 2006.  
So we get outdated bindings that aren't worth a thing today.

If I knew how to make them, I'd do it by myself, but I don't. 😕

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Chananya\_Freiman](https://avatars.discourse-cdn.com/v4/letter/c/ad7895/32.png) [@Chananya\_Freiman](https://rubytalk.org/u/Chananya_Freiman)\
**Post date:** [20 December 2010 21:09 UTC](https://rubytalk.org/t/opengl-support/61201/2 "2010-12-20T21:09:45Z")

</div>

By the way, I don't know much about writing C extensions, but is it  
possible (not for me ☹ ) to tell a Ruby program to open this page  
[http://www.opengl.org/registry/api/gl3.h](http://www.opengl.org/registry/api/gl3.h) and dynamically making the  
bindings from that file?  
If someone could make that, the bindings will be automatically updated  
(you'll just need to run the "bindings maker" and upload the gem using  
the new bindings it created).

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Marcelo1](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@Marcelo1](https://rubytalk.org/u/Marcelo1)\
**Post date:** [21 December 2010 02:24 UTC](https://rubytalk.org/t/opengl-support/61201/3 "2010-12-21T02:24:29Z")

</div>

Sorry for being lazy. Can you point me to an URL to download  
those two? I have a soft spot for OpenGL and I'm one of the  
original authors of GLEW, and I would like to see if I can  
update the bindings for both of those libraries and keep them  
updated.

Thanks,

Marcelo

> **···**
>
> On Mon, Dec 20, 2010 at 14:12, Chananya Freiman \<thebluedragont@gmail.com\> wrote:
> 
> > ruby-opengl only seems to work on Ruby 1.8, and ruby/glew is  
> > from 2006. So we get outdated bindings that aren't worth a  
> > thing today.

---

<div class="post-metadata">

**Author:** ![Andrea\_Fazzi1](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@Andrea\_Fazzi1](https://rubytalk.org/u/Andrea_Fazzi1)\
**Post date:** [21 December 2010 12:55 UTC](https://rubytalk.org/t/opengl-support/61201/4 "2010-12-21T12:55:39Z")

</div>

Chananya Freiman wrote in post #969634:

> Will there ever be updated bindings to OpenGL?  
> I can't understand how there's a language without working bindings to  
> the biggest open source graphics API out there.
> 
> ruby-opengl only seems to work on Ruby 1.8, and ruby/glew is from 2006.  
> So we get outdated bindings that aren't worth a thing today.
> 
> If I knew how to make them, I'd do it by myself, but I don't. 😕

Perhaps, you may be interested in ffi-opengl too:

&nbsp;&nbsp;[GitHub - remogatto/ffi-opengl: A ruby-ffi binding to OpenGL libraries](https://github.com/remogatto/ffi-opengl)

I don't know if it is still working with latest ruby-ffi. In case, I'll  
be happy to accept patches 🙂

Cheers,  
Andrea

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Chananya\_Freiman](https://avatars.discourse-cdn.com/v4/letter/c/ad7895/32.png) [@Chananya\_Freiman](https://rubytalk.org/u/Chananya_Freiman)\
**Post date:** [24 December 2010 19:43 UTC](https://rubytalk.org/t/opengl-support/61201/5 "2010-12-24T19:43:29Z")

</div>

I looked a bit into C extensions and I thought of a pretty easy way of  
making the bindings.  
However, this way isn't really "portable" in the sense that you have to  
run a Ruby file on every computer, and have to have something that can  
create an OpenGL context (I am using GLFW at the moment).

All these steps are done in an rb file, no need to do it manually.

Step 1) Download the gl3.h file from [opengl.org](http://opengl.org)  
Step 2) Create a tiny C extension that creates an OpenGL context, gets  
the OpenGL version supported by the computer, and terminates the  
context.  
Step 3) Start creating the bindings by parsing gl3.h and taking the  
version into consideration.

Parsing should be too hard.

You figure where the first occurrence of "#define GL\_VERSION\_x\_y", where  
x and y are your major and minor parts of the GL version.  
You find the next occurrence of any GL\_VERSION.  
This is where your drivers stop supporting constants, so you parse  
everything that far.

Now, you get the next occurrence of "#define GL\_VERSION\_x\_y", and again  
the next occurrence of any GL\_VERSION.  
This is where the drivers stop supporting actual GL function entry  
points, so you parse the entry points until there.

And...that's basically it.  
The parsing itself is pretty easy.

Constants are a quick one-liner in a String#scan:

data.scan(/#define (GL\_[A-Z0-9\_]+)[\t]+([0-9A-Fx]+)/) { |block|  
&nbsp;&nbsp;&nbsp;&nbsp;f.puts "rb\_define\_const(GL, \"#{block[0]}\", INT2FIX(#{block[1]}));"  
}

Functions are a little harder because of the argument types that need to  
be taken into account, but it shouldn't be too hard (I started working  
on them and then realized that I forgot to remove functions of higher GL  
version then I have so I got tons of linker errors :P).

The main problem of this as I see it is the fact that you must create a  
context to get the GL version.  
Running a Ruby file is sort of an annoyance, but then installing gems is  
more work.  
Having to have a specific library, however, is sort of un-portable and  
annoying.

What do you guys think about this?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Michael\_Brooks](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@Michael\_Brooks](https://rubytalk.org/u/Michael_Brooks)\
**Post date:** [21 December 2010 03:25 UTC](https://rubytalk.org/t/opengl-support/61201/6 "2010-12-21T03:25:27Z")

</div>

"Marcelo" \<marcelo.magallon@gmail.com\> wrote in message news:AANLkTinHKY3ZOKSFZq5zSvq3cL7WFB\_q5E8h6jc3E+m1@mail.gmail.com...

> **···**
>
> > On Mon, Dec 20, 2010 at 14:12, Chananya Freiman \> \<thebluedragont@gmail.com\> wrote:
> > 
> > > ruby-opengl only seems to work on Ruby 1.8, and ruby/glew is  
> > > from 2006. So we get outdated bindings that aren't worth a  
> > > thing today.
> > 
> > Sorry for being lazy. Can you point me to an URL to download  
> > those two? I have a soft spot for OpenGL and I'm one of the  
> > original authors of GLEW, and I would like to see if I can  
> > update the bindings for both of those libraries and keep them  
> > updated.
> > 
> > Thanks,
> > 
> > Marcelo
> 
> Hello Marcelo:
> 
> Ruby Glew [http://rubyforge.org/projects/rubyglew/](http://rubyforge.org/projects/rubyglew/)  
> Ruby OpenGL [http://ruby-opengl.rubyforge.org/](http://ruby-opengl.rubyforge.org/)
> 
> Thanks in advance for anything you do to update these.
> 
> Michael

---

<div class="post-metadata">

**Author:** ![Ralf\_Mueller1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/ralf_mueller1/32/2123_2.png) [@Ralf\_Mueller1](https://rubytalk.org/u/Ralf_Mueller1)\
**Post date:** [21 December 2010 09:03 UTC](https://rubytalk.org/t/opengl-support/61201/7 "2010-12-21T09:03:21Z")

</div>

Hi Marcelo

> &nbsp;&nbsp;Sorry for being lazy. Can you point me to an URL to download  
> &nbsp;&nbsp;those two? I have a soft spot for OpenGL and I'm one of the  
> &nbsp;&nbsp;original authors of GLEW, and I would like to see if I can  
> &nbsp;&nbsp;update the bindings for both of those libraries and keep them  
> &nbsp;&nbsp;updated.

This would be great! Thanx for the work.

regards  
ralf
