GLU Tesselator の謎,解けた!
2000年8月10日
やーれやれ,ずいぶん苦労したぞ.
gluTessVertex の2,3番目の引数が同じサンプルばっかりだったけど,
どうやら2番目がOpenGLが内部で使う座標で,
3番目が vertexCallback の1番目の引数として渡されて,
gluTessBeginPolygon の2番目の引数が vertexCallback の
2番目の引数として渡されるようだ.
それ以前にも,関数の宣言などで CALLBACK をつけるだの色々はまりまくりだった.
typedef struct vd { double v[3]; double rgb[3]; int id; } VertexData; void CALLBACK vertexCallback(GLvoid *vertex, void *user_data) { const VertexData *ver = (VertexData *) vertex; double *data = (double*)user_data; if (ver) printf("pointer(%f,%f,%f)[%f,%f,%f] %d\n",ver->v[0],ver->v[1],ver->v[2], ver->rgb[0],ver->rgb[1],ver->rgb[2], ver->id); else { printf("pointer == NULL!?\n"); return; } if (data) printf("data (%f,%f,%f)\n", data[0],data[1],data[2]); else printf("data == NULL!?\n"); glColor3dv(ver->rgb); glVertex3dv(ver->v); } /* combineCallback is used to create a new vertex when edges * intersect. coordinate location is trivial to calculate, * but weight[4] may be used to average color, normal, or texture * coordinate data. In this program, color is weighted. */ void CALLBACK combineCallback(GLdouble coords[3], VertexData *vertex_data[4], GLfloat weight[4], VertexData **dataOut ) { VertexData *vertex; int i; static id = 100; vertex = (VertexData *) malloc(sizeof(VertexData)); vertex->v[0] = coords[0]; vertex->v[1] = coords[1]; vertex->v[2] = coords[2]; for (i = 0; i < 3; i++) vertex->rgb[i] = weight[0] * vertex_data[0]->rgb[i] + weight[1] * vertex_data[1]->rgb[i] + weight[2] * vertex_data[2]->rgb[i] + weight[3] * vertex_data[3]->rgb[i]; vertex->id = id++; *dataOut = vertex; } gluTessBeginPolygon(tobj, tmp); gluTessBeginContour(tobj); gluTessVertex(tobj, rect[0].v, &rect[0]); gluTessVertex(tobj, rect[1].v, &rect[1]); gluTessVertex(tobj, rect[2].v, &rect[2]); gluTessVertex(tobj, rect[3].v, &rect[3]); gluTessEndContour(tobj); gluTessBeginContour(tobj); gluTessVertex(tobj, tri[0].v, &tri[0]); gluTessVertex(tobj, tri[1].v, &tri[1]); gluTessVertex(tobj, tri[2].v, &tri[2]); gluTessEndContour(tobj); gluTessEndPolygon(tobj); glEndList();
まあなんにせよ,これでタイリングは自前でやる必要がなくなったわけだ.
あとは,このタイリングに渡すポリゴンの頂点を作るのが問題だ.
いや,頂点は計算できてるから,後は並べるだけだ!
あと,ステンシルバッファによる見かけ倒しのきれいな穴!