PHP で OpenGL/GLUT

sotarok 先生に phpopengl なる物を教わったので、試してみたらあっさり動いた。

結果 →

PHP4 用だったのと OpenGL の定数マクロが少し異なるので、少し改造した。

以下、CentOS4 + PHP5 上で build した作業内容詳細。

build 開始

% mkdir phpopengl
% cd phpopengl
% cvs -d:pserver:anonymous@phpopengl.cvs.sourceforge.net:/cvsroot/phpopengl login
% cvs -z3 -d:pserver:anonymous@phpopengl.cvs.sourceforge.net:/cvsroot/phpopengl co -P .
% cd php_opengl
% (cd opengl ; phpize ; ./configure ; make ) # ☆ これで失敗する ☆
% (cd gult   ; phpize ; ./configure ; make )

_EXT

gult はあっさり build 成功。
openglコンパイル時に error が出力された。

/home/yoya/cvs/phpopengl/php_opengl/opengl/php_opengl.c:5779: error: 'GL_COLOR_TABLE_GREEN_SIZE_EXT' undeclared (first use in this function)

どうやら、これらの 〜_EXT は 〜_SGI と同じ値っぽい。


#define 〜_EXT 〜_SGI を片っ端からかけてみて解決。

BYREF_

/home/yoya/cvs/phpopengl/php_opengl/opengl/php_opengl.c:56: error: 'BYREF_FORCE' undeclared here (not in a function)
/home/yoya/cvs/phpopengl/php_opengl/opengl/php_opengl.c:59: error: 'BYREF_NONE' undeclared here (not in a function)

BYREF_... は PHP4 extension の引数定義に使うもので、
PHP5 では ZEND_BEGIN_ARG_INFO を使うらしい。

% grep BYREF_ ~/src/php/php-4.0.0/*/*.h
/home/yoya/src/php/php-4.0.0/Zend/zend.h:#define BYREF_NONE 0
/home/yoya/src/php/php-4.0.0/Zend/zend.h:#define BYREF_FORCE 1
/home/yoya/src/php/php-4.0.0/Zend/zend.h:#define BYREF_ALLOW 2
/home/yoya/src/php/php-4.0.0/Zend/zend.h:#define BYREF_FORCE_REST 3

とりあえず、全部 NULL に define する。
(リフレクションに問題あるらしいけど、そんなの後あと)

/* {{{ arginfo */
#ifdef ZEND_ENGINE_2
#define force_ref_first_arg  NULL
#define force_ref_second_arg NULL
#define force_ref_third_arg  NULL
#define force_ref_fourth_arg NULL
#define force_ref_ninth_arg  NULL
#else
(BYREF_ 何とかしてる場所)
#endif
/* }}} */

github

折角なので、github に登録してみた。

  • 公開鍵を登録 (テキストをWebの登録画面に張り付けるだけ)
  • 手元に repository を作成
  • 手元の master に commit
  • github 上の origin に push

オリジナルのソースを登録

% mkdir phpopengl
% cd phpopengl
% git init
(オリジナルの php_opengl samples をコピーしてくる)
% git add php_opengl samples
% git commit -m 'copy from phpopengl.cvs.sourceforge.net:/cvsroot/phpopengl'
% git remote add origin git@github.com:yoya/phpopengl.git
% git push origin master
|<<

改造分を反映(commit & push)
>||
% emacs php_opengl.h
(編集)
% emacs php_opengl.c
(編集)
% git commit -a
(vi 画面が開くので上の方にコメントを追記)
% git push origin master
 (http://github.com/yoya/phpopengl) 

大問題

phpopengl でなく swfed の問題を見つけてしまった。。。

  • はじめ、サンプルプログラムが動かなかった
  • 何故か、output が redefined されてるって怒られる
  • あれ、SWF Editor を外すと動く。。。
  • ちょw SWF Editor のクラスメソッドが global function で見えてるぅぅぅ。
  • ごめんなさい何とかします。