# OpenGL-0.32g for Apple MacOS X

**URL:** <https://www.ruby-forum.com/t/opengl-0-32g-for-apple-macos-x/53207>\
**Category:** Ruby\
**Created:** [January 29, 2006, 1:22am UTC](https://www.ruby-forum.com/t/opengl-0-32g-for-apple-macos-x/53207 "2006-01-29T01:22:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nitr0z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba9def/32.png) [@nitr0z](https://www.ruby-forum.com/u/nitr0z)\
**Post date:** [January 29, 2006, 1:22am UTC](https://www.ruby-forum.com/t/opengl-0-32g-for-apple-macos-x/53207/1 "2006-01-29T01:22:28Z")

</div>

In case anyone needs this, I’ve uploaded my tweaked version of the  
latest rb-opengl bindings to:

[http://www.lazyatom.com/software/opengl-0.32g.tar.gz](http://www.lazyatom.com/software/opengl-0.32g.tar.gz)

You’ll need the Developer Tools and probably the GLUT source from  
Apple already installed. Here’s the README:

2005-04-26 :: James A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
2006-01-28 :: (Updated to rb-opengl-0.32g)

# Ruby-OpenGL Bindings for Mac OS X

So basically here’s a tweaked version of the original OpenGL module  
for the Mac. To compile, just follow the same instructions as normal:

Build it - don’t worry too much about any warnings:  
$ ruby extconf.rb  
$ make

Test it out:  
$ ruby sample/robot.rb  
(press the ‘e’ and ‘s’ keys to make the “robot” move…)

Install it:  
$ make install  
(or possibly “sudo make install”, depending on where your ruby is)

## Changes I’ve made

extconf.rb:  
Added -framework flags and correct include directories  
Hacked to generate GLUT module even without detection of -lGLUT, since  
mkmf can’t deal with the Mac GLUT framework

\*.c:  
Edited #includes to use \<OpenGL/gl.h\> and \<GLUT/glut.h\>

glut.c:  
I’ve added the function CheckLoop to the GLUT module in line with the  
same function in Apple’s GLUT. GLUT’s MainLoop is blocking and forces  
you to perform additoinal processing using GLUT’s IdleFunc system,  
which can sometimes be very undesirable (particularly if you are using  
Ruby as the glue between two libraries which both feature this type of  
loop). CheckLoop allows you to cycle through a _single_ GLUT  
processing loop, and then returns control to the calling  
thread/process. Thus, by periodically calling CheckLoop, you can get  
the scene to update without having GLUT seize control of the whole  
application.

I’ve also added calls for Glut.GameModeString(mode\_string) and  
Glut.EnterGameMode(), allowing you to switch your application to  
fullscreen.

Finally, a new method GLUT.BitmapCharacterX(char) for displaying  
characters, since there seems to be a problem with the default  
GLUT.BitmapCharacter method.

## Problems

For some reason, including the libraries from the command line fails.  
For instance:

$ irb  
irb(main):001:0\> require ‘opengl’; require ‘glut’  
=\> true

… works fine, but:

$ irb -r opengl  
/usr/local/lib/ruby/site\_ruby/1.8/powerpc-darwin8.0.0/opengl.bundle:  
[BUG] Bus Error  
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0.0]

Abort trap

… clearly fails. You can see the discussion of this problem  
(something unfortunately inherent with IRB on the mac) here:

[http://ruby-talk.org/cgi-bin/scat.rb/~poffice/news2/comp.lang.ruby/23917](http://ruby-talk.org/cgi-bin/scat.rb/~poffice/news2/comp.lang.ruby/23917)

Or the quick fix, detailed here:

[http://ruby-talk.org/cgi-bin/scat.rb/~poffice/news2/comp.lang.ruby/24004](http://ruby-talk.org/cgi-bin/scat.rb/~poffice/news2/comp.lang.ruby/24004)

---

<div class="post-metadata">

**Author:** ![nitr0z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba9def/32.png) [@nitr0z](https://www.ruby-forum.com/u/nitr0z)\
**Post date:** [January 29, 2006, 5:32am UTC](https://www.ruby-forum.com/t/opengl-0-32g-for-apple-macos-x/53207/2 "2006-01-29T05:32:24Z")

</div>

On 1/28/06, James A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> In case anyone needs this, I’ve uploaded my tweaked version of the  
> latest rb-opengl bindings to:

Has anyone used Ruby + OpenGL for anything of interest?

Joe

---

<div class="post-metadata">

**Author:** ![nitr0z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba9def/32.png) [@nitr0z](https://www.ruby-forum.com/u/nitr0z)\
**Post date:** [January 29, 2006, 7:24am UTC](https://www.ruby-forum.com/t/opengl-0-32g-for-apple-macos-x/53207/3 "2006-01-29T07:24:07Z")

</div>

From: “Joe Van D.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> Has anyone used Ruby + OpenGL for anything of interest?

I’ve been stoked by the librend screenshots:

[http://librend.rubyforge.org/wiki/wiki.pl](http://librend.rubyforge.org/wiki/wiki.pl) (Project Page)

For ex:

[http://librend.rubyforge.org/screenshots/picking.png](http://librend.rubyforge.org/screenshots/picking.png)  
[http://librend.rubyforge.org/screenshots/round\_cut.png](http://librend.rubyforge.org/screenshots/round_cut.png)  
[http://librend.rubyforge.org/screenshots/textured\_tram.png](http://librend.rubyforge.org/screenshots/textured_tram.png)  
[http://librend.rubyforge.org/screenshots/topview\_follow\_ghost.jpg](http://librend.rubyforge.org/screenshots/topview_follow_ghost.jpg)

This is looking like an awesome library.

Regards,

Bill

---

<div class="post-metadata">

**Author:** ![nitr0z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba9def/32.png) [@nitr0z](https://www.ruby-forum.com/u/nitr0z)\
**Post date:** [January 29, 2006, 5:51pm UTC](https://www.ruby-forum.com/t/opengl-0-32g-for-apple-macos-x/53207/4 "2006-01-29T17:51:55Z")

</div>

Trying this, I get

objc: failed objc\_getClass(NSObject) for GLUTApplication-\>isa-\>isa  
objc: please link appropriate classes in your program  
Trace/BPT trap

I cleaned out the old opengl.bundle and glut.bundle and re-built the  
bindings from the new package. I have no idea what this error means,  
so any tips would be appreciated 🙂 I do have the GLUT.framework and  
X-Code installed, so I think I’m good there.

---

<div class="post-metadata">

**Author:** ![nitr0z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba9def/32.png) [@nitr0z](https://www.ruby-forum.com/u/nitr0z)\
**Post date:** [January 29, 2006, 9:48am UTC](https://www.ruby-forum.com/t/opengl-0-32g-for-apple-macos-x/53207/5 "2006-01-29T09:48:39Z")

</div>

On 1/29/06, Bill K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [http://librend.rubyforge.org/screenshots/picking.png](http://librend.rubyforge.org/screenshots/picking.png)  
> [http://librend.rubyforge.org/screenshots/round\_cut.png](http://librend.rubyforge.org/screenshots/round_cut.png)  
> [http://librend.rubyforge.org/screenshots/textured\_tram.png](http://librend.rubyforge.org/screenshots/textured_tram.png)  
> [http://librend.rubyforge.org/screenshots/topview\_follow\_ghost.jpg](http://librend.rubyforge.org/screenshots/topview_follow_ghost.jpg)

Here’s a 10MB video of a presentation I made for class using librend:

[http://www.cs.helsinki.fi/u/irkheikk/fx\_final.avi](http://www.cs.helsinki.fi/u/irkheikk/fx_final.avi)  
Needs an XviD codec of some sort, don’t know exactly _what_ sort.

It was more fun than doing the usual powerpoint thing, and a lot more  
work too. But now I can extract all the effects and add them to  
librend proper 🙂

Source at [http://librend.rubyforge.org/fx/fx.rb](http://librend.rubyforge.org/fx/fx.rb) but it’s against an  
old CVS version, and I managed to break stuff in the current CVS, so  
it’s not going to work until the next release of librend.

> This is looking like an awesome library.

Thanks, appreciate it.

Cheers,  
Ilmari

---

<div class="post-metadata">

**Author:** ![nitr0z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba9def/32.png) [@nitr0z](https://www.ruby-forum.com/u/nitr0z)\
**Post date:** [January 29, 2006, 9:08pm UTC](https://www.ruby-forum.com/t/opengl-0-32g-for-apple-macos-x/53207/6 "2006-01-29T21:08:39Z")

</div>

Hmm… the addition of “–framework Foundation” should prevent this  
and ensure that the Obj-C runtime is initialised. Can you confirm that  
your compile includes this flag? (it should be added automatically for  
the darwin platform by the appropriate section in extconf.rb

- james

---

<div class="post-metadata">

**Author:** ![nitr0z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba9def/32.png) [@nitr0z](https://www.ruby-forum.com/u/nitr0z)\
**Post date:** [January 31, 2006, 2:03pm UTC](https://www.ruby-forum.com/t/opengl-0-32g-for-apple-macos-x/53207/7 "2006-01-31T14:03:00Z")

</div>

> It was more fun than doing the usual powerpoint thing, and a lot more  
> work too. But now I can extract all the effects and add them to  
> librend proper 🙂
> 
> Source at [http://librend.rubyforge.org/fx/fx.rb](http://librend.rubyforge.org/fx/fx.rb) but it’s against an  
> old CVS version, and I managed to break stuff in the current CVS, so  
> it’s not going to work until the next release of librend.

Quite impressive 😉

-g.

---

<div class="post-metadata">

**Author:** ![nitr0z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba9def/32.png) [@nitr0z](https://www.ruby-forum.com/u/nitr0z)\
**Post date:** [January 31, 2006, 6:16pm UTC](https://www.ruby-forum.com/t/opengl-0-32g-for-apple-macos-x/53207/8 "2006-01-31T18:16:16Z")

</div>

On 1/29/06, tsuraan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> So, it looks like I’m using the foundation framework. Does ruby need  
> to be compiled with it also?

I dont’ think so - I just compiled it with the normal options and it  
seemed to work fine. I know I’ve had errors like this in the past, but  
I can’t for the life of me remember how I got them to go away! ☹

---

<div class="post-metadata">

**Author:** ![nitr0z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba9def/32.png) [@nitr0z](https://www.ruby-forum.com/u/nitr0z)\
**Post date:** [January 30, 2006, 12:18am UTC](https://www.ruby-forum.com/t/opengl-0-32g-for-apple-macos-x/53207/9 "2006-01-30T00:18:45Z")

</div>

> Hmm… the addition of “–framework Foundation” should prevent this  
> and ensure that the Obj-C runtime is initialised. Can you confirm that  
> your compile includes this flag? (it should be added automatically for  
> the darwin platform by the appropriate section in extconf.rb

The full result of typing ‘make’ is (sorry for the long ugly post):

Now Making glut extend module  
gcc -fno-common -g -O2 -fno-common -pipe -fno-common -I.  
-I/System/Library/Frameworks/OpenGL.framework/Headers  
-I/System/Library/Frameworks/GLUT.framework/Headers -I.  
-I/usr/lib/ruby/1.8/powerpc-darwin7.9.0  
-I/usr/lib/ruby/1.8/powerpc-darwin7.9.0 -I. -c glut.c  
glut.c: In function `glut_KeyboardFunc': glut.c:157: warning: passing arg 1 of`glutKeyboardFunc’ from  
incompatible pointer type  
cc -dynamic -bundle -undefined suppress -flat\_namespace -framework  
OpenGL -framework GLUT -framework Foundation -L"/usr/lib"  
-L"/System/Library/Frameworks/OpenGL.framework/Libraries/" -o  
glut.bundle glut.o -lruby -lGLU -lGL -lpthread -ldl -lobjc -lruby  
Now Making opengl extend module  
gcc -fno-common -g -O2 -fno-common -pipe -fno-common -I.  
-I/System/Library/Frameworks/OpenGL.framework/Headers  
-I/System/Library/Frameworks/GLUT.framework/Headers -I.  
-I/usr/lib/ruby/1.8/powerpc-darwin7.9.0  
-I/usr/lib/ruby/1.8/powerpc-darwin7.9.0 -I. -c glu.c  
glu.c: In function `glu_PickMatrix': glu.c:1185: warning: passing arg 2 of`ary2cint’ from incompatible  
pointer type  
glu.c: In function `glu_Project': glu.c:1224: warning: passing arg 2 of`ary2cint’ from incompatible  
pointer type  
glu.c: In function `glu_UnProject': glu.c:1269: warning: passing arg 2 of`ary2cint’ from incompatible  
pointer type  
gcc -fno-common -g -O2 -fno-common -pipe -fno-common -I.  
-I/System/Library/Frameworks/OpenGL.framework/Headers  
-I/System/Library/Frameworks/GLUT.framework/Headers -I.  
-I/usr/lib/ruby/1.8/powerpc-darwin7.9.0  
-I/usr/lib/ruby/1.8/powerpc-darwin7.9.0 -I. -c ogl.c  
gcc -fno-common -g -O2 -fno-common -pipe -fno-common -I.  
-I/System/Library/Frameworks/OpenGL.framework/Headers  
-I/System/Library/Frameworks/GLUT.framework/Headers -I.  
-I/usr/lib/ruby/1.8/powerpc-darwin7.9.0  
-I/usr/lib/ruby/1.8/powerpc-darwin7.9.0 -I. -c rbogl.c  
cc -dynamic -bundle -undefined suppress -flat\_namespace -framework  
OpenGL -framework GLUT -framework Foundation -L"/usr/lib"  
-L"/System/Library/Frameworks/OpenGL.framework/Libraries/" -o  
opengl.bundle glu.o ogl.o rbogl.o -lruby -lGLU -lGL -lpthread -ldl  
-lobjc -lruby

So, it looks like I’m using the foundation framework. Does ruby need  
to be compiled with it also?
