From 73f90db03816d4e70e4fff5cc630668f44be1af3 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Fri, 26 Jan 2007 09:28:39 +0000 Subject: Added experimental code for filling maps (do not support arcs). Contributed by Intuilab. --- generic/Map.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 7 deletions(-) (limited to 'generic/Map.c') diff --git a/generic/Map.c b/generic/Map.c index 0ceb966..fd61709 100644 --- a/generic/Map.c +++ b/generic/Map.c @@ -1309,6 +1309,28 @@ Draw(ZnItem item) */ #ifdef GL static void +MapRenderVectors(ZnTriStrip *tristrip) +{ + unsigned int i, j, num_points; + ZnPoint *points; + + for (i = 0; i < tristrip->num_strips; i++) { + num_points = tristrip->strips[i].num_points; + points = tristrip->strips[i].points; + if (tristrip->strips[i].fan) { + glBegin(GL_TRIANGLE_FAN); + } + else { + glBegin(GL_TRIANGLE_STRIP); + } + for (j = 0; j < num_points; j++, points++) { + glVertex2d(points->x, points->y); + } + glEnd(); + } +} + +static void Render(ZnItem item) { ZnWInfo *wi = item->wi; @@ -1333,15 +1355,54 @@ Render(ZnItem item) alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); if (map->filled) { - if (ZnListSize(map->vectors) || ZnListSize(map->arcs)) { - /* TODO_GL: Need to have a tesselated polygon then - * fill it either using ZnRenderTile or solid. - */ - if (map->fill_pattern != ZnUnspecifiedImage) { - /* Fill stippled */ + // + // TODO: This code doesn't handle pattern/tile and filled + // arcs are not supported. The tesselation data is not + // cached for future reuse, it is redone for each render + // pass. + // Render only vectors + if (ZnListSize(map->vectors)) { + ZnTriStrip tristrip; + GLdouble v[3]; + ZnCombineData *cdata, *cnext; + + line_width = 1.0; + glLineWidth(line_width); + ZnSetLineStyle(wi, ZN_LINE_SIMPLE); + cnt = ZnListSize(map->vectors); + points = ZnListArray(map->vectors); + + /* Init our TriStrip */ + tristrip.num_strips = 0; + tristrip.strips = NULL; + + /* Start tessellation */ + gluTessProperty(ZnTesselator.tess, GLU_TESS_BOUNDARY_ONLY, (GLdouble) GL_FALSE); + gluTessBeginPolygon(ZnTesselator.tess, &tristrip); + gluTessBeginContour(ZnTesselator.tess); + + for (i =0; i < cnt; i += 2) { + v[0] = points[i].x; + v[1] = points[i].y; + v[2] = 0; + gluTessVertex(ZnTesselator.tess, v, &points[i]); } - else { + + gluTessEndContour(ZnTesselator.tess); + gluTessEndPolygon(ZnTesselator.tess); + + cdata = ZnTesselator.combine_list; + while (cdata) { + ZnTesselator.combine_length--; + cnext = cdata->next; + ZnFree(cdata); + cdata = cnext; } + ZnTesselator.combine_list = NULL; + + /* Render our vectors*/ + MapRenderVectors(&tristrip); + ZnTriFree(&tristrip); } } else { /* Not filled */ -- cgit v1.1