ブログランキング・にほんブログ村へ


iPhone/iPad用潜水艦ゲームアプリ ソナーエコー iTunesにて公開中

2013年05月23日

[OpenGL ES2.0]gl_NormalMatrix 逆転置行列の正体

OpenGLシェーダの勉強をしてると、gl_NormalMatrixとかglModelViewMatrixとか他にもいろいろ予約済み定義済みの
変数名が出てくるわけだけど、同じOpenGLでも ESがついちゃうとこういうのが全然存在しない。
glPushMatrixとかないくらいだし。

じゃぁどうすんのかっていうと自分で勝手に適当な名前で uniformしてね、ってことになるわけだけど
glModelViewMatrixはともかくとしてgl_NormalMatrix、こいつがなんなのかずっとすっきりしてなかった。

だって法線専用マトリクスって、法線も同じ空間にあるわけだからモデルビューマトリクスで変換でいいじゃん。って思うわけ。
実際シェーダで法線用マトリクスの代わりにモデルビューマトリクスを使っても(vec4にいったん拡張して)結果に変わりはない。
しかもなんかこれ、モデルビューマトリクスの逆転置行列とかなんか難しいこといってるし。

reflectを扱うにあたって、ここ、いい加減なままだと気持ち悪いんできちんと理解することにした。




色々調べてみて現時点で一応納得いった説明を自分の理解でまとめてみて、
腑に落ちなかったものを
腑に落ちるものに変換する。
自分なりに。



まず、前提として法線の変換も基本的にモデルビューマトリクスでいい。

ただ、法線はベクトルで位置情報がないんで、vec4でなくvec3である。だから変換マトリクスもmat4でなく移動(translate)成分のないmat3になる(mat4の左上3x3を取ってきたもの)必要がある。

じゃあどうしてモデルビューマトリクスを単にmat4 -> mat3じゃだめなのかっていうと、スケーリングが関係する。


線分 p0 - p1のxのみを2倍したところを図にしてみた。それと同じ変換を法線ベクトルにも施す。



そうすると、法線ベクトルは直角じゃなくなってて、もはや法線ではなくなってしまってる。


自分の実験で、モデルビューマトリクスで法線も変換しても結果が変わらなかったのはスケーリングせずにメッシュモデルを1:1で表示してたからだったわけだ。



これは補正するにはどうすればいいのかっていうと。



この図でも線分のxを2倍している。
赤が上の図と同じ、xを2倍した法線ベクトル。
そして、緑が、逆にxを1/2倍した法線ベクトル。

こんなふうに線分の倍数の逆数を掛けると、いい具合にスケーリングにも対応できる。


だから、法線の変換マトリクスは、x,y,z軸回転についてはそのまま、スケールについては逆数を掛けたものになってほしい。

そんな都合のいいマトリクス…それが逆転置行列。変換の理屈はよくわかんないけど。
名前がなんか似てるけど逆行列ではない。ろくに調べもしないで逆行列みたいなもんかな、と思ってたから理解が余計におかしくなってたんだけど。

じゃあこれでx,y,z全部が2倍になったりする場合はどうなるの、って考えると法線のx,y,zについての長さが全部1/2になってしまう。つまり法線全体が短くなってしまうので、光源ベクトルとの内積も半分になり、暗くなってしまう。

だから、法線に変換マトリクスを掛けたら必ずnormalizeが必要だったのだ。
OpenGL ES1.1のとき、glScaleで大きくしたモデルが glEnable(GL_NORMALIZE); 無しだと暗くなってしまったのはこういうわけだったのだ。ついにその謎が解けた。


しかし逆に考えると、スケーリングをxだけとかzだけとかしないでいつもx、y、zを同率でやってる場合、こんな難しいこと考えなくてもモデルビューマトリクスの右上3x3でそのまま法線も変換できる。

ただし、この場合、たとえば2倍だと法線のx,y,zも2倍になってしまうから今度は逆に明るくなってしまう。
つまり、やっぱりnormalizeは必要だ。


というわけで今日の勉強、おしまい。
posted by みこあいさ at 19:21| OpenGL

2012年07月06日

OpenGL 文字を書く

iPhoneの簡単なゲームを書いていて、アイテムをゲットしたときに感じるひっかかり感がずっと気になっていた。
微妙にコマ落ちしてる感じ。気づかない人もいるかも?ってレベル。
fpsを計ってみると、普段はほとんど60fpsかそれに近い値なのにその瞬間だけ確かに50fpsとかに下がってる。
それで、音を疑って色々いじってみたけどそれはほとんど無関係だった。
結果としては文字。OpenGLは文字を書く機能がなく、それを代用する機能として文字列をテクスチャに展開してそれを表示するようになっていた。
アイテムをゲットするとスコアがあがる。すると画面上の Score 0 が Score 10になり、Score 20...と変わるたびに新しいテクスチャを生成しなければならないのだが、これが結構重いらしい。しかもこれ、テクスチャを毎度作ってると遅すぎるのでキャッシュする仕組みになっていたから、次々変わることで古いキャッシュの破棄まで発生していた。

それを避ける方法として、以前用意した自前の2次ベジェのベクタフォントを展開し表示するようにしたが、これもそんなに速くない。
ベジェで発生する点が多すぎるのだ。
それで0x00〜0x7fに限りベクタフォントを展開したストロークをOpenGLのglDrawArrays( GL_LINES,0,pointNum );で一発で書けるようにVOBにあらかじめ送っておく方法を試してみた。
しかしこれだと、確かに速くはなるが
glVertexPointer( 3,GL_FLOAT,3*4+4,(char *)NULL +0 );
glColorPointer(4, GL_UNSIGNED_BYTE,3*4+4,NULL+3*4 );
こんな感じで色もVOBで一気に指定するので色が自由にならない。
じゃぁ座標だけVOBにして色のほうだけその都度発生ってことにしたら?と考えていたら、そもそもglVertexPointerに直接送れる形式で配列に持ってりゃVOBと大差ないんでは?と思った。
そんな誰でも考えそうなこと、どっかにあるに違いないとぐぐったのだがなぜか見つからなかった。探し方が悪かったのかもしれないけど。
(ちなみにぐぐってみたら、OpenGLで文字を出すのはみんな苦労してるようだった。ほとんどはテクスチャを使っていた)

それならプログラマ的に使いやすいように直線ベクタフォントにして、じかにコード内の配列におけたらもっと便利そうだというんで作ってみた。
処理速度はVOBのときと大差ない。色の方はその都度処理なんで実行時にいかようにでもなってなかなか使い勝手がよい。

見た目はこんな感じで綺麗かといえばひどいものだけど。

上のほうの赤い文字のほうね。ABCDEF...ってあるほう。
青い方はテクスチャ。

このスクショにも出てるように、固定文字列なんかはテクスチャで綺麗な文字を表示して、リアルタイム性のある文字列はベクタフォントを使えばよさそう。


せっかく作ったんでプログラムをおいておく。
iOS用に書いたけど、汎用性の乏しいObjective-Cは使わず全てC(よくしんないけどC99あたり?)で書いてあるので他のOpenGL環境でも使えると思う。
ヘッダなどは適宜環境用のものをインクリュードすること。
iOSだと
#import <OpenGLES/ES1/gl.h>

フォーマットは激しく単純なんでプログラムをみれば即わかるレベル。

使い方は

どこかで一回初期化。
GLLineFont__init();


描画。
GLLineFont__drawString( 20,-30,"ABCDEFGHIJKLMNOPQRSTUVWXYZ",16,16,0xff8f8fff,1 );
yは使ってる投影座標系によるがマイナスにしたりする必要があるかもしれない。

いないと思うけど、もしこれ使う人がいたらここが発祥だと書いてもらえるとうれしい。

static float fontSrc[] = {
// Vector font for OpenGL by Miko Aisa @ Ankohouse / 2012.7.6
//////code=0~31 NOT defined
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
//////code=32
1, //defined
0.5933, //font width
0, //num of pt
//////code=33
1, //defined
0.3233, //font width
4, //num of pt
0.1666,-0.0649,0,0.1683,-0.6816,0,0.1683,-0.7716,0,0.1683,-0.8516,0,
//////code=34
1, //defined
0.4467, //font width
4, //num of pt
0.1650,-0.0283,0,0.0750,-0.1183,0,0.3400,-0.0250,0,0.2400,-0.1250,0,
//////code=35
1, //defined
0.8600, //font width
8, //num of pt
0.2516,-0.0683,0,0.2516,-0.8516,0,0.5933,-0.0699,0,0.5933,-0.8500,0,0.0699,-0.2583,0,0.7850,-0.2583,0,0.0717,-0.6349,0,0.7850,-0.6349,0,
//////code=36
1, //defined
0.5099, //font width
24, //num of pt
0.2650,-0.0366,0,0.2650,-0.8799,0,0.4233,-0.2017,0,0.3400,-0.1183,0,0.3400,-0.1183,0,0.1716,-0.1183,0,0.1716,-0.1183,0,0.0883,-0.2017,0,
0.0883,-0.2017,0,0.0883,-0.3833,0,0.0883,-0.3833,0,0.1666,-0.4616,0,0.1666,-0.4616,0,0.3500,-0.4616,0,0.3500,-0.4616,0,0.4250,-0.5283,0,
0.4250,-0.5283,0,0.4250,-0.7567,0,0.4250,-0.7567,0,0.3533,-0.8199,0,0.3533,-0.8199,0,0.1533,-0.8199,0,0.1533,-0.8199,0,0.0717,-0.7383,0,
//////code=37
1, //defined
0.7166, //font width
34, //num of pt
0.6233,-0.0667,0,0.0817,-0.8500,0,0.1600,-0.1716,0,0.1083,-0.2233,0,0.1083,-0.2233,0,0.1083,-0.3199,0,0.1083,-0.3199,0,0.1600,-0.3716,0,
0.1600,-0.3716,0,0.2583,-0.3716,0,0.2583,-0.3716,0,0.3050,-0.3250,0,0.3050,-0.3250,0,0.3050,-0.2200,0,0.3050,-0.2200,0,0.2533,-0.1700,0,
0.2533,-0.1700,0,0.1600,-0.1716,0,0.4966,-0.5817,0,0.4449,-0.6333,0,0.4449,-0.6333,0,0.4449,-0.7300,0,0.4449,-0.7300,0,0.4966,-0.7816,0,
0.4966,-0.7816,0,0.5950,-0.7816,0,0.5950,-0.7816,0,0.6417,-0.7350,0,0.6417,-0.7350,0,0.6417,-0.6299,0,0.6417,-0.6299,0,0.5900,-0.5800,0,
0.5900,-0.5800,0,0.4966,-0.5817,0,
//////code=38
1, //defined
0.6899, //font width
22, //num of pt
0.6216,-0.7516,0,0.1233,-0.2833,0,0.1233,-0.2833,0,0.1233,-0.1750,0,0.1233,-0.1750,0,0.2266,-0.0717,0,0.2266,-0.0717,0,0.3483,-0.0717,0,
0.3483,-0.0717,0,0.4417,-0.1650,0,0.4417,-0.1650,0,0.4417,-0.2816,0,0.4417,-0.2816,0,0.0767,-0.5633,0,0.0767,-0.5633,0,0.0767,-0.7549,0,
0.0767,-0.7549,0,0.1949,-0.8516,0,0.1949,-0.8516,0,0.3766,-0.8516,0,0.3766,-0.8516,0,0.6333,-0.5850,0,
//////code=39
1, //defined
0.2633, //font width
4, //num of pt
0.1033,-0.0383,0,0.1766,-0.0383,0,0.1766,-0.0383,0,0.0767,-0.2733,0,
//////code=40
1, //defined
0.3933, //font width
10, //num of pt
0.2983,-0.0383,0,0.1816,-0.1200,0,0.1816,-0.1200,0,0.0883,-0.3116,0,0.0883,-0.3116,0,0.0883,-0.6483,0,0.0883,-0.6483,0,0.1899,-0.8000,0,
0.1899,-0.8000,0,0.2950,-0.8783,0,
//////code=41
1, //defined
0.3300, //font width
10, //num of pt
0.0622,-0.0416,0,0.1788,-0.1233,0,0.1788,-0.1233,0,0.2722,-0.3149,0,0.2722,-0.3149,0,0.2722,-0.6516,0,0.2722,-0.6516,0,0.1705,-0.8033,0,
0.1705,-0.8033,0,0.0656,-0.8817,0,
//////code=42
1, //defined
0.5667, //font width
6, //num of pt
0.2783,-0.0633,0,0.2783,-0.8533,0,0.0483,-0.1850,0,0.5016,-0.7416,0,0.5049,-0.1783,0,0.0583,-0.7533,0,
//////code=43
1, //defined
0.6566, //font width
4, //num of pt
0.0616,-0.4633,0,0.6083,-0.4633,0,0.3283,-0.1566,0,0.3283,-0.7733,0,
//////code=44
1, //defined
0.2700, //font width
4, //num of pt
0.1550,-0.7549,0,0.1983,-0.7549,0,0.1983,-0.7549,0,0.0950,-0.9316,0,
//////code=45
1, //defined
0.7067, //font width
2, //num of pt
0.0616,-0.4600,0,0.6500,-0.4600,0,
//////code=46
1, //defined
0.1899, //font width
2, //num of pt
0.0916,-0.7783,0,0.1083,-0.8183,0,
//////code=47
1, //defined
0.7366, //font width
2, //num of pt
0.6727,-0.0577,0,0.0972,-0.8711,0,
//////code=48
1, //defined
0.5966, //font width
16, //num of pt
0.1700,-0.0699,0,0.0683,-0.2017,0,0.0683,-0.2017,0,0.0683,-0.7266,0,0.0683,-0.7266,0,0.1683,-0.8533,0,0.1683,-0.8533,0,0.4283,-0.8533,0,
0.4283,-0.8533,0,0.5150,-0.7283,0,0.5150,-0.7283,0,0.5150,-0.1917,0,0.5150,-0.1917,0,0.4083,-0.0683,0,0.4083,-0.0683,0,0.1700,-0.0699,0,
//////code=49
1, //defined
0.3133, //font width
4, //num of pt
0.0566,-0.1766,0,0.1716,-0.0683,0,0.1716,-0.0683,0,0.1716,-0.8550,0,
//////code=50
1, //defined
0.6466, //font width
12, //num of pt
0.0866,-0.1750,0,0.1899,-0.0717,0,0.1899,-0.0717,0,0.4399,-0.0717,0,0.4399,-0.0717,0,0.5516,-0.1833,0,0.5516,-0.1833,0,0.5516,-0.3849,0,
0.5516,-0.3849,0,0.0717,-0.8500,0,0.0717,-0.8500,0,0.5649,-0.8500,0,
//////code=51
1, //defined
0.5133, //font width
22, //num of pt
0.0833,-0.1516,0,0.1500,-0.0717,0,0.1500,-0.0717,0,0.3817,-0.0717,0,0.3817,-0.0717,0,0.4666,-0.1516,0,0.4666,-0.1516,0,0.4666,-0.3516,0,
0.4666,-0.3516,0,0.3317,-0.4550,0,0.3317,-0.4550,0,0.4666,-0.5550,0,0.4666,-0.5550,0,0.4666,-0.7716,0,0.4666,-0.7716,0,0.3844,-0.8533,0,
0.3844,-0.8533,0,0.1433,-0.8533,0,0.1433,-0.8533,0,0.0600,-0.7700,0,0.2372,-0.4544,0,0.3283,-0.4544,0,
//////code=52
1, //defined
0.6967, //font width
6, //num of pt
0.6400,-0.6016,0,0.0600,-0.6016,0,0.0600,-0.6016,0,0.4816,-0.0649,0,0.4816,-0.0649,0,0.4816,-0.8533,0,
//////code=53
1, //defined
0.6800, //font width
14, //num of pt
0.5433,-0.0699,0,0.1266,-0.0699,0,0.1266,-0.0699,0,0.1266,-0.4616,0,0.1266,-0.4616,0,0.4266,-0.4616,0,0.4266,-0.4616,0,0.5483,-0.5833,0,
0.5483,-0.5833,0,0.5483,-0.7433,0,0.5483,-0.7433,0,0.4417,-0.8500,0,0.4417,-0.8500,0,0.1183,-0.8500,0,
//////code=54
1, //defined
0.5900, //font width
20, //num of pt
0.3966,-0.0699,0,0.2100,-0.0699,0,0.2100,-0.0699,0,0.0850,-0.1949,0,0.0850,-0.1949,0,0.0850,-0.7617,0,0.0850,-0.7617,0,0.1783,-0.8550,0,
0.1783,-0.8550,0,0.4166,-0.8550,0,0.4166,-0.8550,0,0.5000,-0.7716,0,0.5000,-0.7716,0,0.5000,-0.5583,0,0.5000,-0.5583,0,0.4050,-0.4633,0,
0.4050,-0.4633,0,0.1783,-0.4633,0,0.1783,-0.4633,0,0.0900,-0.5516,0,
//////code=55
1, //defined
0.7233, //font width
4, //num of pt
0.1066,-0.0717,0,0.6433,-0.0717,0,0.6433,-0.0717,0,0.2416,-0.8500,0,
//////code=56
1, //defined
0.5866, //font width
30, //num of pt
0.1816,-0.0667,0,0.0750,-0.1733,0,0.0750,-0.1733,0,0.0750,-0.3716,0,0.0750,-0.3716,0,0.1633,-0.4600,0,0.1633,-0.4600,0,0.0466,-0.5817,0,
0.0466,-0.5817,0,0.0466,-0.7549,0,0.0466,-0.7549,0,0.1299,-0.8516,0,0.1299,-0.8516,0,0.4766,-0.8516,0,0.4766,-0.8516,0,0.5500,-0.7633,0,
0.5500,-0.7633,0,0.5500,-0.5833,0,0.5500,-0.5833,0,0.4366,-0.4600,0,0.4366,-0.4600,0,0.5099,-0.3867,0,0.5099,-0.3867,0,0.5099,-0.1716,0,
0.5099,-0.1716,0,0.4000,-0.0649,0,0.4000,-0.0649,0,0.1816,-0.0667,0,0.1600,-0.4600,0,0.4350,-0.4600,0,
//////code=57
1, //defined
0.5866, //font width
16, //num of pt
0.2050,-0.8533,0,0.5067,-0.3672,0,0.5067,-0.3672,0,0.5067,-0.1750,0,0.5067,-0.1750,0,0.4000,-0.0683,0,0.4000,-0.0683,0,0.1622,-0.0683,0,
0.1622,-0.0683,0,0.0622,-0.1683,0,0.0622,-0.1683,0,0.0622,-0.3650,0,0.0622,-0.3650,0,0.1466,-0.4611,0,0.1466,-0.4611,0,0.4422,-0.4616,0,
//////code=58
1, //defined
0.2900, //font width
4, //num of pt
0.1200,-0.6349,0,0.1755,-0.6906,0,0.1200,-0.1772,0,0.1755,-0.2327,0,
//////code=59
1, //defined
0.3400, //font width
6, //num of pt
0.1500,-0.6349,0,0.2055,-0.6906,0,0.2055,-0.6906,0,0.1150,-0.8416,0,0.1500,-0.1772,0,0.2055,-0.2327,0,
//////code=60
1, //defined
0.6000, //font width
4, //num of pt
0.4777,-0.0577,0,0.0800,-0.4555,0,0.0800,-0.4555,0,0.4888,-0.8644,0,
//////code=61
1, //defined
0.6733, //font width
4, //num of pt
0.0800,-0.3694,0,0.6044,-0.3694,0,0.0800,-0.5494,0,0.6044,-0.5494,0,
//////code=62
1, //defined
0.6333, //font width
4, //num of pt
0.1733,-0.0594,0,0.5711,-0.4572,0,0.5711,-0.4572,0,0.1622,-0.8661,0,
//////code=63
1, //defined
0.6700, //font width
16, //num of pt
0.1089,-0.1605,0,0.2022,-0.0672,0,0.2022,-0.0672,0,0.4733,-0.0672,0,0.4733,-0.0672,0,0.5688,-0.1627,0,0.5688,-0.1627,0,0.5688,-0.3705,0,
0.5688,-0.3705,0,0.4777,-0.4616,0,0.4777,-0.4616,0,0.3400,-0.4616,0,0.3400,-0.4616,0,0.3400,-0.7000,0,0.3355,-0.7716,0,0.3355,-0.8539,0,
//////code=64
1, //defined
0.7866, //font width
30, //num of pt
0.1111,-0.7422,0,0.1111,-0.3305,0,0.1111,-0.3305,0,0.2466,-0.1949,0,0.2466,-0.1949,0,0.5778,-0.1949,0,0.5778,-0.1949,0,0.7155,-0.3328,0,
0.7155,-0.3328,0,0.7155,-0.7333,0,0.7155,-0.7333,0,0.6044,-0.8444,0,0.6044,-0.8444,0,0.5488,-0.7689,0,0.5488,-0.7689,0,0.5488,-0.5144,0,
0.5488,-0.5144,0,0.4955,-0.4611,0,0.4955,-0.4611,0,0.3339,-0.4611,0,0.3339,-0.4611,0,0.2605,-0.5344,0,0.2605,-0.5344,0,0.2605,-0.7599,0,
0.2605,-0.7599,0,0.3428,-0.8422,0,0.3428,-0.8422,0,0.4733,-0.8422,0,0.4733,-0.8422,0,0.5400,-0.7755,0,
//////code=65
1, //defined
0.8366, //font width
6, //num of pt
0.0616,-0.8583,0,0.3766,-0.0633,0,0.3766,-0.0633,0,0.7800,-0.8566,0,0.1666,-0.5955,0,0.6378,-0.5955,0,
//////code=66
1, //defined
0.6566, //font width
20, //num of pt
0.0911,-0.8533,0,0.0911,-0.0644,0,0.0911,-0.0644,0,0.4377,-0.0644,0,0.4377,-0.0644,0,0.5755,-0.1777,0,0.5755,-0.1777,0,0.5755,-0.3533,0,
0.5755,-0.3533,0,0.4355,-0.4555,0,0.4355,-0.4555,0,0.5800,-0.5733,0,0.5800,-0.5733,0,0.5822,-0.7556,0,0.5822,-0.7556,0,0.4578,-0.8533,0,
0.4578,-0.8533,0,0.0911,-0.8533,0,0.0911,-0.4533,0,0.4355,-0.4533,0,
//////code=67
1, //defined
0.6866, //font width
14, //num of pt
0.5983,-0.1833,0,0.4833,-0.0683,0,0.4833,-0.0683,0,0.1766,-0.0683,0,0.1766,-0.0683,0,0.0683,-0.1766,0,0.0683,-0.1766,0,0.0683,-0.7466,0,
0.0683,-0.7466,0,0.1766,-0.8550,0,0.1766,-0.8550,0,0.5067,-0.8550,0,0.5067,-0.8550,0,0.6000,-0.7617,0,
//////code=68
1, //defined
0.7233, //font width
12, //num of pt
0.1100,-0.0699,0,0.1100,-0.8516,0,0.1100,-0.8516,0,0.5133,-0.8516,0,0.5133,-0.8516,0,0.6483,-0.7183,0,0.6483,-0.7183,0,0.6466,-0.2200,0,
0.6466,-0.2200,0,0.4966,-0.0699,0,0.4966,-0.0699,0,0.1100,-0.0699,0,
//////code=69
1, //defined
0.6833, //font width
8, //num of pt
0.5850,-0.0699,0,0.1000,-0.0699,0,0.1000,-0.0699,0,0.1000,-0.8533,0,0.1000,-0.8533,0,0.6033,-0.8533,0,0.1033,-0.4583,0,0.4816,-0.4583,0,
//////code=70
1, //defined
0.6583, //font width
6, //num of pt
0.5649,-0.0699,0,0.0800,-0.0699,0,0.0800,-0.0699,0,0.0800,-0.8533,0,0.0833,-0.4583,0,0.4616,-0.4583,0,
//////code=71
1, //defined
0.6766, //font width
18, //num of pt
0.6050,-0.1833,0,0.4900,-0.0683,0,0.4900,-0.0683,0,0.1833,-0.0683,0,0.1833,-0.0683,0,0.0750,-0.1766,0,0.0750,-0.1766,0,0.0750,-0.7466,0,
0.0750,-0.7466,0,0.1833,-0.8550,0,0.1833,-0.8550,0,0.5133,-0.8550,0,0.5133,-0.8550,0,0.6066,-0.7617,0,0.6066,-0.7617,0,0.6066,-0.4633,0,
0.6066,-0.4633,0,0.3416,-0.4633,0,
//////code=72
1, //defined
0.7400, //font width
6, //num of pt
0.0800,-0.0633,0,0.0800,-0.8583,0,0.6633,-0.0633,0,0.6633,-0.8583,0,0.0783,-0.4600,0,0.6600,-0.4600,0,
//////code=73
1, //defined
0.3267, //font width
6, //num of pt
0.0916,-0.0699,0,0.2516,-0.0699,0,0.0916,-0.8516,0,0.2516,-0.8516,0,0.1750,-0.0767,0,0.1750,-0.8455,0,
//////code=74
1, //defined
0.4000, //font width
12, //num of pt
0.1766,-0.0699,0,0.3366,-0.0699,0,0.2599,-0.0767,0,0.2599,-0.7472,0,0.2599,-0.7472,0,0.2067,-0.9033,0,0.2067,-0.9033,0,0.1000,-0.9966,0,
0.1000,-0.9966,0,-0.0333,-0.9950,0,-0.0333,-0.9950,0,-0.1150,-0.9200,0,
//////code=75
1, //defined
0.6816, //font width
8, //num of pt
0.1116,-0.0600,0,0.1116,-0.8550,0,0.1133,-0.4666,0,0.5833,-0.0633,0,0.1733,-0.4266,0,0.5750,-0.8550,0,0.5750,-0.8550,0,0.5750,-0.8550,0,
//////code=76
1, //defined
0.7250, //font width
4, //num of pt
0.0983,-0.0633,0,0.0983,-0.8533,0,0.0983,-0.8533,0,0.6317,-0.8533,0,
//////code=77
1, //defined
0.8100, //font width
8, //num of pt
0.0583,-0.8550,0,0.0583,-0.0633,0,0.0583,-0.0633,0,0.3950,-0.4850,0,0.3950,-0.4850,0,0.7383,-0.0616,0,0.7383,-0.0616,0,0.7383,-0.8583,0,
//////code=78
1, //defined
0.7000, //font width
6, //num of pt
0.0817,-0.8550,0,0.0817,-0.0649,0,0.0817,-0.0649,0,0.6233,-0.8550,0,0.6233,-0.8550,0,0.6233,-0.0633,0,
//////code=79
1, //defined
0.7933, //font width
32, //num of pt
0.7133,-0.4591,0,0.6807,-0.6341,0,0.6807,-0.6341,0,0.6210,-0.7367,0,0.6210,-0.7367,0,0.5389,-0.8111,0,0.5389,-0.8111,0,0.3983,-0.8516,0,
0.3983,-0.8516,0,0.2651,-0.8165,0,0.2651,-0.8165,0,0.1755,-0.7367,0,0.1755,-0.7367,0,0.1088,-0.6293,0,0.1088,-0.6293,0,0.0833,-0.4591,0,
0.0833,-0.4591,0,0.1001,-0.3100,0,0.1001,-0.3100,0,0.1755,-0.1816,0,0.1755,-0.1816,0,0.2580,-0.1060,0,0.2580,-0.1060,0,0.3983,-0.0667,0,
0.3983,-0.0667,0,0.5351,-0.1080,0,0.5351,-0.1080,0,0.6210,-0.1816,0,0.6210,-0.1816,0,0.6891,-0.3147,0,0.6891,-0.3147,0,0.7133,-0.4591,0,
//////code=80
1, //defined
0.6367, //font width
12, //num of pt
0.0900,-0.8533,0,0.0900,-0.0644,0,0.0900,-0.0644,0,0.4366,-0.0644,0,0.4366,-0.0644,0,0.5744,-0.1777,0,0.5744,-0.1777,0,0.5744,-0.3533,0,
0.5744,-0.3533,0,0.4266,-0.4555,0,0.4266,-0.4555,0,0.0955,-0.4555,0,
//////code=81
1, //defined
0.7556, //font width
34, //num of pt
0.6911,-0.4591,0,0.6584,-0.6341,0,0.6584,-0.6341,0,0.5988,-0.7367,0,0.5988,-0.7367,0,0.5167,-0.8111,0,0.5167,-0.8111,0,0.3761,-0.8516,0,
0.3761,-0.8516,0,0.2429,-0.8165,0,0.2429,-0.8165,0,0.1533,-0.7367,0,0.1533,-0.7367,0,0.0865,-0.6293,0,0.0865,-0.6293,0,0.0611,-0.4591,0,
0.0611,-0.4591,0,0.0779,-0.3100,0,0.0779,-0.3100,0,0.1533,-0.1816,0,0.1533,-0.1816,0,0.2358,-0.1060,0,0.2358,-0.1060,0,0.3761,-0.0667,0,
0.3761,-0.0667,0,0.5129,-0.1080,0,0.5129,-0.1080,0,0.5988,-0.1816,0,0.5988,-0.1816,0,0.6669,-0.3147,0,0.6669,-0.3147,0,0.6911,-0.4591,0,
0.4489,-0.6555,0,0.6489,-0.8555,0,
//////code=82
1, //defined
0.6566, //font width
14, //num of pt
0.0955,-0.8533,0,0.0955,-0.0644,0,0.0955,-0.0644,0,0.4422,-0.0644,0,0.4422,-0.0644,0,0.5800,-0.1777,0,0.5800,-0.1777,0,0.5800,-0.3533,0,
0.5800,-0.3533,0,0.4322,-0.4555,0,0.4322,-0.4555,0,0.1011,-0.4555,0,0.4288,-0.4644,0,0.5800,-0.8555,0,
//////code=83
1, //defined
0.5633, //font width
22, //num of pt
0.4844,-0.1528,0,0.4011,-0.0694,0,0.4011,-0.0694,0,0.1750,-0.0694,0,0.1750,-0.0694,0,0.0916,-0.1528,0,0.0916,-0.1528,0,0.0916,-0.3833,0,
0.0916,-0.3833,0,0.1700,-0.4616,0,0.1700,-0.4616,0,0.4028,-0.4616,0,0.4028,-0.4616,0,0.4861,-0.5455,0,0.4861,-0.5455,0,0.4861,-0.7705,0,
0.4861,-0.7705,0,0.4061,-0.8511,0,0.4061,-0.8511,0,0.1566,-0.8511,0,0.1566,-0.8511,0,0.0750,-0.7694,0,
//////code=84
1, //defined
0.6955, //font width
4, //num of pt
0.0844,-0.0711,0,0.6244,-0.0711,0,0.3577,-0.0733,0,0.3577,-0.8533,0,
//////code=85
1, //defined
0.7166, //font width
10, //num of pt
0.0755,-0.0667,0,0.0755,-0.7155,0,0.0755,-0.7155,0,0.2155,-0.8555,0,0.2155,-0.8555,0,0.5178,-0.8555,0,0.5178,-0.8555,0,0.6555,-0.7178,0,
0.6555,-0.7178,0,0.6555,-0.0688,0,
//////code=86
1, //defined
0.7433, //font width
4, //num of pt
0.0600,-0.0667,0,0.3622,-0.8533,0,0.3622,-0.8533,0,0.6911,-0.0644,0,
//////code=87
1, //defined
0.9200, //font width
8, //num of pt
0.0266,-0.0667,0,0.2444,-0.8533,0,0.2444,-0.8533,0,0.4266,-0.4467,0,0.4266,-0.4467,0,0.6466,-0.8511,0,0.6466,-0.8511,0,0.8711,-0.0644,0,
//////code=88
1, //defined
0.7067, //font width
4, //num of pt
0.0555,-0.0667,0,0.6511,-0.8533,0,0.6511,-0.0667,0,0.0555,-0.8533,0,
//////code=89
1, //defined
0.7166, //font width
6, //num of pt
0.0627,-0.0644,0,0.3672,-0.4666,0,0.3672,-0.4666,0,0.6605,-0.0644,0,0.3688,-0.4622,0,0.3688,-0.8555,0,
//////code=90
1, //defined
0.7567, //font width
6, //num of pt
0.1177,-0.0683,0,0.6644,-0.0683,0,0.6644,-0.0683,0,0.0889,-0.8533,0,0.0889,-0.8533,0,0.6689,-0.8533,0,
//////code=91
1, //defined
0.4467, //font width
6, //num of pt
0.3505,-0.0400,0,0.1127,-0.0400,0,0.1127,-0.0400,0,0.1127,-0.8855,0,0.1127,-0.8855,0,0.3505,-0.8855,0,
//////code=92
1, //defined
0.6989, //font width
10, //num of pt
0.0516,-0.0644,0,0.3561,-0.4666,0,0.3561,-0.4666,0,0.6494,-0.0644,0,0.3577,-0.4622,0,0.3577,-0.8555,0,0.1489,-0.4555,0,0.5778,-0.4555,0,
0.1466,-0.6466,0,0.5800,-0.6466,0,
//////code=93
1, //defined
0.4233, //font width
6, //num of pt
0.0961,-0.0400,0,0.3339,-0.0400,0,0.3339,-0.0400,0,0.3339,-0.8855,0,0.3339,-0.8855,0,0.0961,-0.8855,0,
//////code=94
1, //defined
0.4467, //font width
4, //num of pt
0.0488,-0.1866,0,0.2155,-0.0200,0,0.2155,-0.0200,0,0.3822,-0.1866,0,
//////code=95
1, //defined
0.7366, //font width
2, //num of pt
0.0400,-0.8533,0,0.6955,-0.8533,0,
//////code=96
1, //defined
0.4399, //font width
4, //num of pt
0.1800,-0.0355,0,0.3088,-0.0355,0,0.3088,-0.0355,0,0.1511,-0.3222,0,
//////code=97
1, //defined
0.7200, //font width
16, //num of pt
0.5233,-0.5477,0,0.2639,-0.8489,0,0.2639,-0.8489,0,0.0822,-0.8489,0,0.0822,-0.8489,0,0.0822,-0.4555,0,0.0822,-0.4555,0,0.2377,-0.3000,0,
0.2377,-0.3000,0,0.4444,-0.3000,0,0.4444,-0.3000,0,0.5244,-0.3799,0,0.5244,-0.3799,0,0.5244,-0.7200,0,0.5244,-0.7200,0,0.6533,-0.8489,0,
//////code=98
1, //defined
0.5222, //font width
12, //num of pt
0.0822,-0.0711,0,0.0822,-0.8511,0,0.0822,-0.8511,0,0.3505,-0.8511,0,0.3505,-0.8511,0,0.4611,-0.7405,0,0.4611,-0.7405,0,0.4611,-0.5433,0,
0.4611,-0.5433,0,0.3489,-0.4311,0,0.3489,-0.4311,0,0.0866,-0.4311,0,
//////code=99
1, //defined
0.5533, //font width
14, //num of pt
0.5049,-0.4100,0,0.3900,-0.2950,0,0.3900,-0.2950,0,0.1611,-0.2950,0,0.1611,-0.2950,0,0.0527,-0.4033,0,0.0527,-0.4033,0,0.0527,-0.7466,0,
0.0527,-0.7466,0,0.1611,-0.8550,0,0.1611,-0.8550,0,0.4133,-0.8550,0,0.4133,-0.8550,0,0.5067,-0.7617,0,
//////code=100
1, //defined
0.5450, //font width
12, //num of pt
0.4469,-0.0711,0,0.4469,-0.8511,0,0.4469,-0.8511,0,0.1869,-0.8511,0,0.1869,-0.8511,0,0.0763,-0.7405,0,0.0763,-0.7405,0,0.0763,-0.5416,0,
0.0763,-0.5416,0,0.1885,-0.4294,0,0.1885,-0.4294,0,0.4424,-0.4294,0,
//////code=101
1, //defined
0.5683, //font width
16, //num of pt
0.4755,-0.8466,0,0.1714,-0.8466,0,0.1714,-0.8466,0,0.0694,-0.7435,0,0.0694,-0.7435,0,0.0694,-0.4165,0,0.0694,-0.4165,0,0.1714,-0.3133,0,
0.1714,-0.3133,0,0.3868,-0.3133,0,0.3868,-0.3133,0,0.4951,-0.4229,0,0.4951,-0.4229,0,0.4951,-0.5593,0,0.4951,-0.5593,0,0.0778,-0.5593,0,
//////code=102
1, //defined
0.4933, //font width
8, //num of pt
0.0450,-0.4600,0,0.4399,-0.4600,0,0.2333,-0.8566,0,0.2333,-0.2733,0,0.2333,-0.2733,0,0.3066,-0.2000,0,0.3066,-0.2000,0,0.4283,-0.2000,0,
//////code=103
1, //defined
0.6066, //font width
22, //num of pt
0.1800,-0.2966,0,0.1016,-0.3750,0,0.1016,-0.3750,0,0.1016,-0.7166,0,0.1016,-0.7166,0,0.1750,-0.7900,0,0.1750,-0.7900,0,0.4449,-0.7900,0,
0.4449,-0.7900,0,0.5133,-0.7216,0,0.5133,-0.7216,0,0.5133,-0.3700,0,0.5133,-0.3700,0,0.4383,-0.2950,0,0.4383,-0.2950,0,0.1800,-0.2966,0,
0.5117,-0.7266,0,0.5117,-0.8516,0,0.5117,-0.8516,0,0.3799,-0.9833,0,0.3799,-0.9833,0,0.1116,-0.9833,0,
//////code=104
1, //defined
0.5283, //font width
10, //num of pt
0.0683,-0.0717,0,0.0683,-0.8566,0,0.0667,-0.5150,0,0.1516,-0.4300,0,0.1516,-0.4300,0,0.3817,-0.4300,0,0.3817,-0.4300,0,0.4533,-0.5016,0,
0.4533,-0.5016,0,0.4533,-0.8533,0,
//////code=105
1, //defined
0.2866, //font width
4, //num of pt
0.1400,-0.1516,0,0.1400,-0.2150,0,0.1400,-0.2916,0,0.1400,-0.8566,0,
//////code=106
1, //defined
0.3233, //font width
10, //num of pt
0.1666,-0.1516,0,0.1666,-0.2150,0,0.1666,-0.2916,0,0.1666,-0.8566,0,0.1666,-0.8566,0,0.1150,-0.9250,0,0.1150,-0.9250,0,0.0117,-0.9983,0,
0.0117,-0.9983,0,-0.0616,-0.9983,0,
//////code=107
1, //defined
0.4550, //font width
6, //num of pt
0.0600,-0.0699,0,0.0600,-0.8533,0,0.3683,-0.2916,0,0.0600,-0.5550,0,0.0600,-0.5550,0,0.4033,-0.8550,0,
//////code=108
1, //defined
0.3066, //font width
8, //num of pt
0.0600,-0.0767,0,0.1500,-0.0767,0,0.1500,-0.0767,0,0.1500,-0.7883,0,0.1500,-0.7883,0,0.2133,-0.8516,0,0.2133,-0.8516,0,0.2766,-0.8516,0,
//////code=109
1, //defined
0.6483, //font width
18, //num of pt
0.0649,-0.2916,0,0.0649,-0.8550,0,0.0699,-0.3833,0,0.1600,-0.2933,0,0.1600,-0.2933,0,0.2416,-0.2933,0,0.2416,-0.2933,0,0.3283,-0.3799,0,
0.3283,-0.3799,0,0.3283,-0.8583,0,0.3300,-0.3833,0,0.4200,-0.2933,0,0.4200,-0.2933,0,0.5016,-0.2933,0,0.5016,-0.2933,0,0.5883,-0.3799,0,
0.5883,-0.3799,0,0.5883,-0.8583,0,
//////code=110
1, //defined
0.5566, //font width
10, //num of pt
0.0667,-0.2916,0,0.0667,-0.8550,0,0.0717,-0.4583,0,0.1716,-0.3000,0,0.1716,-0.3000,0,0.3849,-0.3000,0,0.3849,-0.3000,0,0.4933,-0.4550,0,
0.4933,-0.4550,0,0.4933,-0.8583,0,
//////code=111
1, //defined
0.5855, //font width
32, //num of pt
0.5422,-0.5747,0,0.5165,-0.6992,0,0.5165,-0.6992,0,0.4695,-0.7721,0,0.4695,-0.7721,0,0.4047,-0.8250,0,0.4047,-0.8250,0,0.2939,-0.8539,0,
0.2939,-0.8539,0,0.1888,-0.8289,0,0.1888,-0.8289,0,0.1183,-0.7721,0,0.1183,-0.7721,0,0.0656,-0.6957,0,0.0656,-0.6957,0,0.0455,-0.5747,0,
0.0455,-0.5747,0,0.0588,-0.4686,0,0.0588,-0.4686,0,0.1183,-0.3773,0,0.1183,-0.3773,0,0.1832,-0.3235,0,0.1832,-0.3235,0,0.2939,-0.2955,0,
0.2939,-0.2955,0,0.4017,-0.3250,0,0.4017,-0.3250,0,0.4695,-0.3773,0,0.4695,-0.3773,0,0.5231,-0.4719,0,0.5231,-0.4719,0,0.5422,-0.5747,0,
//////code=112
1, //defined
0.5144, //font width
12, //num of pt
0.0644,-0.9983,0,0.0644,-0.2933,0,0.0644,-0.2933,0,0.3583,-0.2933,0,0.3583,-0.2933,0,0.4327,-0.3688,0,0.4327,-0.3688,0,0.4327,-0.7689,0,
0.4327,-0.7689,0,0.3583,-0.8333,0,0.3583,-0.8333,0,0.0699,-0.8333,0,
//////code=113
1, //defined
0.5055, //font width
12, //num of pt
0.4373,-0.9933,0,0.4373,-0.2933,0,0.4373,-0.2933,0,0.1484,-0.2933,0,0.1484,-0.2933,0,0.0739,-0.3688,0,0.0739,-0.3688,0,0.0739,-0.7605,0,
0.0739,-0.7605,0,0.1484,-0.8250,0,0.1484,-0.8250,0,0.4317,-0.8250,0,
//////code=114
1, //defined
0.5611, //font width
8, //num of pt
0.0755,-0.2916,0,0.0755,-0.8550,0,0.0805,-0.4583,0,0.1805,-0.3000,0,0.1805,-0.3000,0,0.3939,-0.3000,0,0.3939,-0.3000,0,0.5022,-0.4550,0,
//////code=115
1, //defined
0.4622, //font width
22, //num of pt
0.4078,-0.3772,0,0.3244,-0.2939,0,0.3244,-0.2939,0,0.1516,-0.2939,0,0.1516,-0.2939,0,0.0683,-0.3772,0,0.0683,-0.3772,0,0.0683,-0.4766,0,
0.0683,-0.4766,0,0.1466,-0.5550,0,0.1466,-0.5550,0,0.3261,-0.5550,0,0.3261,-0.5550,0,0.4094,-0.6389,0,0.4094,-0.6389,0,0.4094,-0.7705,0,
0.4094,-0.7705,0,0.3294,-0.8511,0,0.3294,-0.8511,0,0.1333,-0.8511,0,0.1333,-0.8511,0,0.0516,-0.7694,0,
//////code=116
1, //defined
0.4567, //font width
8, //num of pt
0.0500,-0.2983,0,0.4100,-0.2983,0,0.2350,-0.1866,0,0.2350,-0.7516,0,0.2350,-0.7516,0,0.3033,-0.8533,0,0.3033,-0.8533,0,0.4183,-0.8533,0,
//////code=117
1, //defined
0.5750, //font width
10, //num of pt
0.4995,-0.8602,0,0.4995,-0.2969,0,0.4945,-0.6935,0,0.3945,-0.8519,0,0.3945,-0.8519,0,0.1812,-0.8519,0,0.1812,-0.8519,0,0.0728,-0.6969,0,
0.0728,-0.6969,0,0.0728,-0.2935,0,
//////code=118
1, //defined
0.5717, //font width
4, //num of pt
0.0516,-0.2650,0,0.2766,-0.8883,0,0.2766,-0.8883,0,0.5250,-0.2633,0,
//////code=119
1, //defined
0.6967, //font width
8, //num of pt
0.0483,-0.2933,0,0.2300,-0.8566,0,0.2300,-0.8566,0,0.3433,-0.4350,0,0.3433,-0.4350,0,0.4983,-0.8550,0,0.4983,-0.8550,0,0.6417,-0.2883,0,
//////code=120
1, //defined
0.5767, //font width
4, //num of pt
0.0550,-0.2950,0,0.5233,-0.8583,0,0.5233,-0.2950,0,0.0550,-0.8583,0,
//////code=121
1, //defined
0.4483, //font width
4, //num of pt
0.0233,-0.2916,0,0.2433,-0.7716,0,0.4333,-0.2916,0,0.1683,-0.9983,0,
//////code=122
1, //defined
0.4449, //font width
6, //num of pt
0.0500,-0.2933,0,0.4100,-0.2933,0,0.4100,-0.2933,0,0.0366,-0.8566,0,0.0366,-0.8566,0,0.4200,-0.8566,0,
//////code=123
1, //defined
0.3700, //font width
16, //num of pt
0.3133,-0.0483,0,0.1917,-0.0483,0,0.1917,-0.0483,0,0.1266,-0.1133,0,0.1266,-0.1133,0,0.1266,-0.4383,0,0.1266,-0.4383,0,0.0616,-0.4700,0,
0.0616,-0.4700,0,0.1283,-0.5083,0,0.1283,-0.5083,0,0.1283,-0.8083,0,0.1283,-0.8083,0,0.1983,-0.8783,0,0.1983,-0.8783,0,0.3300,-0.8783,0,
//////code=124
1, //defined
0.2966, //font width
2, //num of pt
0.1566,-0.0683,0,0.1566,-0.8566,0,
//////code=125
1, //defined
0.3799, //font width
16, //num of pt
0.0616,-0.0483,0,0.1833,-0.0483,0,0.1833,-0.0483,0,0.2483,-0.1133,0,0.2483,-0.1133,0,0.2483,-0.4383,0,0.2483,-0.4383,0,0.3133,-0.4700,0,
0.3133,-0.4700,0,0.2466,-0.5083,0,0.2466,-0.5083,0,0.2466,-0.8083,0,0.2466,-0.8083,0,0.1766,-0.8783,0,0.1766,-0.8783,0,0.0450,-0.8783,0,
//////code=126
1, //defined
0.7483, //font width
10, //num of pt
0.0433,-0.5067,0,0.1417,-0.4083,0,0.1417,-0.4083,0,0.3033,-0.4083,0,0.3033,-0.4083,0,0.4000,-0.5049,0,0.4000,-0.5049,0,0.5883,-0.5049,0,
0.5883,-0.5049,0,0.6949,-0.3983,0,
//////code=127 ( Unknown Charactor )
1, //defined
0.5483, //font width
12, //num of pt
0.0633,-0.0699,0,0.4816,-0.0699,0,0.4816,-0.0699,0,0.4816,-0.8566,0,0.4816,-0.8566,0,0.0633,-0.8566,0,0.0633,-0.8566,0,0.0633,-0.0699,0,
0.4766,-0.0733,0,0.0667,-0.8550,0,0.0633,-0.0750,0,0.4783,-0.8550,0,
};
typedef struct Font { //直線フォントクラス
bool bAvil;
float width;
long ptNum;
float const* ppt;
} Font;

static Font fonts[ 128 ];

//初期化
void GLLineFont__init( void ){
float const* ps = fontSrc;
int code = 0;
while( code<128 ){
Font* pf = &fonts[ code ];

if( *ps++ == 0 ){ // not defined
pf->bAvil = false;
}else{
pf->bAvil = true;
pf->width = *ps++;
pf->ptNum = ( long )*ps++;
pf->ppt = ps;
ps += pf->ptNum * 3;
}
code++;
}
}

//文字列の描画
void GLLineFont__drawString( float x,float y,char const* string,float xsize,float ysize,long color,float charSpace ){
glPushMatrix();
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState(GL_COLOR_ARRAY);

glTranslatef( x,y,0 );
glScalef( xsize,ysize,1 );

enum {
VERTEXMAX = 64
};
unsigned char colors[ VERTEXMAX*4 ];
{
long* p = ( long* )colors;
for( int i=0;i= 128 )c = 0x7F; // unknown code

Font const* pf = &fonts[ c ];

if( !pf->bAvil ){
pf = &fonts[ 0x7f ]; //undefined code
}
if( pf->bAvil ){
if( pf->ptNum > 0 ){
glVertexPointer(3,GL_FLOAT,0,pf->ppt );
glColorPointer(4,GL_UNSIGNED_BYTE,0,colors);

glDrawArrays(GL_LINES,0,pf->ptNum );
}

float xd = pf->width + cs;
glTranslatef( xd,0,0 );

x += xd;
}
}
glDisableClientState( GL_COLOR_ARRAY );
glPopMatrix();
}
posted by みこあいさ at 12:48| OpenGL

2012年06月15日

OpenGL glScalefで暗くなる問題解決

OpenGLでメッシュモデルをglScalefで拡大すると暗くなる問題(逆に縮小すると真っ白になる)だが、理由がわかった。

glScalefは持っているベクトルを全てスケールするらしく、そうすると法線を定義しているベクトル情報も拡大縮小してしまうようだ。

いうまでもなく法線は単位ベクトルではなくてはならない。
面の明るさは光の入射ベクトルと法線ベクトルの内積で決まるはずなので、これは無理か…と思ったら法線の長さを単位ベクトル扱いにしてくれる指定があった。

glEnable( GL_NORMALIZE );

これで法線の長さがいいかげんでも描画の時に単位ベクトルにしてくれる。

余計な計算が増えるので遅くなるとかいう記述にも当たったが、やってみると自分のモデル程度では全く問題がなかった。

glScalefでメッシュモデルを描画時に自由に拡大縮小できるといろいろ応用範囲が増えて便利だ。
posted by みこあいさ at 12:57| OpenGL