GLUT for ruby
先週から、マイケル、マイケルでTVやネットは大騒ぎになっている。ネットでは、アクセスが DoSとなって、サーバーが落ちたとか。
ムーン・ウォークを解説する振り付け師が登場してたので、にわかにレッスンを受けて みたけど、出来そうで出来ない技ですなあ。あの機敏な動きと言い、黒->白への変身と 言い、きっと彼はUFOから降りてきた人に違いない。
さもなければ、あの動き30FPSのテープを60FPSで再生したかも知れないな。でも、私は あのロボットみたいな動きより、ファラの方が好きだ。ああ、すっかりおっさんだよ。 (by たださん)。ご冥福をお祈りします。
ああ、そうそう、普段はTVなんて余り見ないけど、 LLTVなら、見てもいいかな。プログラムがまだ、発表になって ないけど、チケットだけは売り出しが始まったようだし。
ruby-opengl on FreeBSD
老舗のruby-openglが有ったので入れてみた。 「このモジュールはruby-1.4.3で動作確認しています」 なんて書かれていて、時代を彷彿させられる。 思えば、私がperlからrubyへスイッチしたのもこの頃だったよなあ。
サンプルが付いていたので、ざっと見てみると、hello.rb そうか、何はなくても、 hello から始まるんだなと思って、開いてみると、
#
#Copyright (c) 1993-1997, Silicon Graphics, Inc.
#ALL RIGHTS RESERVED
#Permission to use, copy, modify, and distribute this software for
#any purpose and without fee is hereby granted, provided that the above
#copyright notice appear in all copies and that both the copyright notice
#and this permission notice appear in supporting documentation, and that
#the name of Silicon Graphics, Inc. not be used in advertising
#or publicity pertaining to distribution of the software without specific,
#written prior permission.
#
#THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
#AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
#INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
#FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
#GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
#SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
#KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
#LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
#THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
#ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
#ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
#POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
#
#US Government Users Restricted Rights
#Use, duplication, or disclosure by the Government is subject to
#restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
#(c)(1)(ii) of the Rights in Technical Data and Computer Software
#clause at DFARS 252.227-7013 and/or in similar or successor
#clauses in the FAR or the DOD or NASA FAR Supplement.
#Unpublished-- rights reserved under the copyright laws of the
#United States. Contractor/manufacturer is Silicon Graphics,
#Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
#
#OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
#
#
#hello.c
#This is a simple, introductory OpenGL program.
#
require "opengl"
require "glut"
display = Proc.new {
GL.Clear (GL::COLOR_BUFFER_BIT);
GL.Color(1.0, 1.0, 1.0);
GL.Begin(GL::POLYGON);
GL.Vertex(0.25, 0.25, 0.0);
GL.Vertex(0.75, 0.25, 0.0);
GL.Vertex(0.75, 0.75, 0.0);
GL.Vertex(0.25, 0.75, 0.0);
GL.End();
GL.Flush();
}
def init
GL.ClearColor(0.0, 0.0, 0.0, 0.0);
GL.MatrixMode(GL::PROJECTION);
GL.LoadIdentity();
GL.Ortho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
end
GLUT.Init
GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB);
GLUT.InitWindowSize(250, 250);
GLUT.InitWindowPosition(100, 100);
GLUT.CreateWindow("hello");
init();
GLUT.DisplayFunc(display);
GLUT.MainLoop();
今はなき Silicon Graphics, Inc. ですか。そうそう、たまたま、CQ出版のインターフェース誌 をちょっと立ち読みしてきたけど、組み込みでも、OpenGL EX とか言う、OpenGLのサブセット が使われているんですね。
虎は死して皮を残し。IT企業は死して規格を残す。これまた、Firefoxもしかり。こちらは 進化が止まらず、そろそろ 3.5ですか。モンスターになり過ぎて、死滅しないように願います。
ruby-opengl on WindowsXP
はて、Windows方面では動くかな? FreeBSDのそれを持ってきてやってみると
c:\sakae\opengl>ruby extconf.rb i386-mswin32 checking for main() in opengl32.lib... no checking for main() in Mesaopengl32.lib... no "can't create OpenGL module!" *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.
予想はしてたけど、見事にエラー。仰せに従って、ログを見ると
c:\sakae\opengl>more mkmf.log
have_library: checking for main() in opengl32.lib... -------------------- no
"cl -nologo -Feconftest -I. -Ic:/app/ruby/lib/ruby/1.8/i386-mswin32 -I. -Ic:/app/ruby/lib/ruby/1.8/i386-mswin32 -MD -Zi -O2b2xg- -G6 conftest.c oldnames.lib
user32.lib advapi32.lib ws2_32.lib -link -libpath:"." -libpath:"c:/app/ruby/lib" -stack:0x2000000"
checked program was:
/* begin */
1: #define WIN32_LEAN_AND_MEAN
2: #include <winsock2.h>
3: #include <windows.h>
4:
5: /*top*/
6: int main() { return 0; }
7: int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
/* end */
あのー、clって、Common Lispの事でしょうか? すっかり、私の嗜好を読まれてるなあ! なんて冗談はやめておく。無料版のVC++ (2005|2008|2010)のどれを入れても、動かん だろうな。
諦めきれずに、extconf.rbを開いてみると、cygwin版もサポートしてるようだから、ひょっと したら、cyginな人は幸せになれるかも知れない。
このままでは悔しいので、 gemの総本山へ行って、 gem版が無いか探してみる。
Ruby bindings for OpenGL and GLUT - ruby-opengl is software that lets you write OpenGL programs in Ruby. Specifically, it primarily consists of extension modules that wrap OpenGL and GLUT. こんなのが有ったので、頂いてきた。
普通は、gem install ruby-opengl で、オンラインインストールが楽なんだけど、私の所 では、ウィルス避けの火壁に遮られて、サーバと通信出来ないので、gem玉を手元に 持って来る事にした。(依存関係があると面倒だけど...)
c:\sakae\tmp>gem install ruby-opengl-0.60.1.gem -l
Building native extensions. This could take a while...
ERROR: Error installing ruby-opengl-0.60.1.gem:
ERROR: Failed to build gem native extension.
c:/app/ruby/bin/ruby.exe -rubygems c:/app/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake RUBYARCHDIR=c:/app/ruby/lib/ruby/gems/1.8/gems/ruby-opengl-0.60.1/lib
RUBYLIBDIR=c:/app/ruby/lib/ruby/gems/1.8/gems/ruby-opengl-0.60.1/lib
ruby mkrf_conf.rb
(in c:/app/ruby/lib/ruby/gems/1.8/gems/ruby-opengl-0.60.1)
call rake --nosearch
cl -nologo -MD -Zi -O2b2xg- -G6 -DWIN32 -DRUBY_VERSION=186 -Ic:/app/ruby/include -Ic:/app/ruby/lib/ruby/1.8/i386-mswin32 -Ic:/app/ruby/lib/ruby/site_ruby/1.8 -I. -c gl-1.0-1.1.c
(in c:/app/ruby/lib/ruby/gems/1.8/gems/ruby-opengl-0.60.1/ext/gl)
'cl' は、内部コマンドまたは外部コマンド、
操作可能なプログラムまたはバッチ ファイルとして認識されていません。
rake aborted!
Command failed with status (1): [cl -nologo -MD -Zi -O2b2xg- -G6 -DWIN32 ...]
c:/app/ruby/lib/ruby/gems/1.8/gems/ruby-opengl-0.60.1/ext/gl/rakefile:29
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [call rake --nosearch...]
c:/app/ruby/lib/ruby/gems/1.8/gems/ruby-opengl-0.60.1/rakefile:61
(See full trace by running task with --trace)
Gem files will remain installed in c:/app/ruby/lib/ruby/gems/1.8/gems/ruby-opengl-0.60.1 for inspection.
Results logged to c:/app/ruby/lib/ruby/gems/1.8/gems/ruby-opengl-0.60.1/gem_make.out
また、clが無いってさー。Windowsの伝統に則って、binary配布しないのか。誰もが、M$に 金を貢とは思えないよ。責任者に一言文句を垂れておきたいぞ。誰にメールすればいいん?
gem玉を展開すると、data.tar.gz と metadata.tar.gzが出てきて、そのうちのmetadataの 方に、案内が書いてあったよ。
email: ruby-opengl-devel@rubyforge.org homepage: http://ruby-opengl.rubyforge.org
このままでは埒があかないので、rakeとかの仕組み等を点検してたら,,,,
デフォでruby-openglが入っていたよ
そう、rubyのサンプルフォルダーに、OpenGL-0.500なんてのが置いてあった。と言う事は デフォでこれが試せるようになっているはず。ならば、証拠探し。
c:\app\ruby\lib\ruby\site_ruby\1.8\i386-msvcrt>ruby -v ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] c:\app\ruby\lib\ruby\site_ruby\1.8\i386-msvcrt>ls -l -rw- 24693 2007-12-14 23:50 fcgi.so -rw- 413771 2007-12-14 23:43 gl.so -rw- 57421 2007-12-14 23:43 glu.so -rw- 53327 2007-12-14 23:43 glut.so -rw- 106605 2007-12-14 23:48 odbc.so -rw- 110702 2007-12-14 23:43 swin.so -rw- 45163 2007-12-14 23:46 xmlparser.so -rw- 41068 2007-12-14 23:24 zlib.so
このruby、確かここから取って きて入れたやつだ。なんだか、灯台元暗しだったなあ。
サンプルをダブルクリックすると、ちゃんと綺麗な図が表示されましたよ。