- procedure DrawSection_AsTesslator;
- var i, x, y, fNumber: Integer;
- t: TGLUTess;
- v: TTessCoords;
- procedure gtCombine(coords: TTessCoords; vertex_data: TTessVertex_data; weight: TTessWeight; var DataOut: TTessDataOut); stdcall;
- var fVertex: pVertex;
- begin
- new(fVertex);
- fVertex^.Vertex[1]:= coords[0];
- fVertex^.Vertex[2]:= coords[1];
- fVertex^.Vertex[3]:= coords[2];
- DataOut:= @fVertex^.Vertex;
- end;
- procedure gtBegin(AMode: Integer); stdcall;
- begin
- TessMode:= AMode;
- TessIndex:= 0;
- end;
- procedure gtVertex(Vertex: Pointer); stdcall;
- { This callback is invoked when the tesselator creates a new group of
- triangles. The atype parameter can be either GL_TRIANGLES, GL_TRIANGLE_FAN
- or GL_TRIANGLE_STRIP. }
- begin
- TessPoints[TessIndex]:= Vertex;
- Inc(TessIndex);
- case TessMode of
- GL_TRIANGLES: begin
- if TessIndex = 3 then begin
- glBegin(GL_TRIANGLES);
- glVertex3fv(TessPoints[0]);
- glVertex3fv(TessPoints[1]);
- glVertex3fv(TessPoints[2]);
- glEnd;
- TessIndex:= 0;
- end;
- end;
- GL_TRIANGLE_STRIP: begin
- if (TessIndex = 3) then begin
- if odd(TessIndex) then begin // needed only in 3D for hidden face removal
- glBegin(GL_TRIANGLES);
- glVertex3fv(TessPoints[0]);
- glVertex3fv(TessPoints[1]);
- glVertex3fv(TessPoints[2]);
- glEnd;
- end else begin
- glBegin(GL_TRIANGLES);
- glVertex3fv(TessPoints[1]);
- glVertex3fv(TessPoints[2]);
- glVertex3fv(TessPoints[0]);
- glEnd;
- end;
- TessPoints[0]:= TessPoints[1];
- TessPoints[1]:= TessPoints[2];
- TessIndex:= 2;
- end;
- end;
- GL_TRIANGLE_FAN: begin
- if TessIndex = 3 then begin
- glBegin(GL_TRIANGLES);
- glVertex3fv(TessPoints[0]);
- glVertex3fv(TessPoints[1]);
- glVertex3fv(TessPoints[2]);
- glEnd;
- TessPoints[1]:= TessPoints[2];
- TessIndex:= 2;
- end;
- end;
- end;
- end;
- procedure gtError(Error: Integer); stdcall;
- begin
- // ShowMessage('GLU Tessellate error #' + IntToStr(Error) + ' : ' + gluErrorString(Error));
- end;
- begin
- t:= gluNewTess;
- gluTessProperty(t, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD);
- // gluTessCallBack(t, GLU_TESS_ERROR, @gtError);
- gluTessCallBack(t, GLU_TESS_BEGIN, @gtBegin);
- // gluTessCallBack(t,GLU_TESS_END_DATA ,@gtEndData);
- gluTessCallBack(t, GLU_TESS_VERTEX, @gtVertex);
- gluTessCallBack(t, GLU_TESS_COMBINE, @gtCombine);
- gluTessBeginPolygon(t, nil);
- gluTessBeginContour(t);
- gluTessVertex(t, v, @Current_Vertex^.Vertex);
- ........... mehrere Punkte
- gluTessEndContour(t);
- ..... evtl mehrere konturen
- gluTessEndPolygon(t);
- gluDeleteTess(t);
- end;