diff options
Diffstat (limited to 'generic')
-rw-r--r-- | generic/Curve.c | 135 |
1 files changed, 104 insertions, 31 deletions
diff --git a/generic/Curve.c b/generic/Curve.c index 07e686e..23933d9 100644 --- a/generic/Curve.c +++ b/generic/Curve.c @@ -320,6 +320,7 @@ Clone(Item item) } for (i = 0; i < cv->shape.num_contours; i++) { cv->shape.contours[i].num_points = conts[i].num_points; + cv->shape.contours[i].cw = conts[i].cw; cv->shape.contours[i].points = ZnMalloc(conts[i].num_points*sizeof(ZnPoint)); memcpy(cv->shape.contours[i].points, conts[i].points, conts[i].num_points*sizeof(ZnPoint)); @@ -638,7 +639,8 @@ CurveTessError(GLenum errno, static void UpdateTristrip(CurveItem cv, - ZnPoly *poly) + ZnPoly *poly, + ZnBool revert) { WidgetInfo *wi = ((Item) cv)->wi; ZnCombineData *cdata, *cnext; @@ -657,19 +659,42 @@ UpdateTristrip(CurveItem cv, if (cv->tristrip.num_strips == 0) { gluTessProperty(wi->tess, GLU_TESS_BOUNDARY_ONLY, GL_FALSE); gluTessBeginPolygon(wi->tess, cv); - for (j = 0; j < poly->num_contours; j++){ - gluTessBeginContour(wi->tess); - /*printf("Début contour %d num_points %d %d\n", - j, poly->contours[j].num_points, poly->contours[j].cw);*/ - for (i = 0; i < poly->contours[j].num_points; i++) { - /*printf("%g@%g ", poly->contours[j].points[i].x, poly->contours[j].points[i].y);*/ - v[0] = poly->contours[j].points[i].x; - v[1] = poly->contours[j].points[i].y; - v[2] = 0; - gluTessVertex(wi->tess, v, &poly->contours[j].points[i]); - } - /*printf("\n");*/ - gluTessEndContour(wi->tess); + /* + * We need to take care of the final (after transformation) winding + * direction of the polygon in order to have the right tesselation + * taking place. + */ + if (!revert) { + for (j = 0; j < poly->num_contours; j++){ + gluTessBeginContour(wi->tess); + /*printf("Début contour %d num_points %d\n", + j, poly->contours[j].num_points);*/ + for (i = 0; i < poly->contours[j].num_points; i++) { + /*printf("%g@%g ", poly->contours[j].points[i].x, poly->contours[j].points[i].y);*/ + v[0] = poly->contours[j].points[i].x; + v[1] = poly->contours[j].points[i].y; + v[2] = 0; + gluTessVertex(wi->tess, v, &poly->contours[j].points[i]); + } + /*printf("\n");*/ + gluTessEndContour(wi->tess); + } + } + else { + for (j = 0; j < poly->num_contours; j++){ + gluTessBeginContour(wi->tess); + /*printf("revert Début contour %d num_points %d\n", + j, poly->contours[j].num_points);*/ + for (i = poly->contours[j].num_points-1; i >= 0; i--) { + /*printf("%g@%g ", poly->contours[j].points[i].x, poly->contours[j].points[i].y);*/ + v[0] = poly->contours[j].points[i].x; + v[1] = poly->contours[j].points[i].y; + v[2] = 0; + gluTessVertex(wi->tess, v, &poly->contours[j].points[i]); + } + /*printf("\n");*/ + gluTessEndContour(wi->tess); + } } gluTessEndPolygon(wi->tess); cdata = wi->tess_combine_list; @@ -685,7 +710,8 @@ UpdateTristrip(CurveItem cv, static void UpdateOutlines(CurveItem cv, - ZnPoly *poly) + ZnPoly *poly, + ZnBool revert) { WidgetInfo *wi = ((Item) cv)->wi; ZnCombineData *cdata, *cnext; @@ -704,15 +730,35 @@ UpdateOutlines(CurveItem cv, if (cv->outlines.num_contours == 0) { gluTessProperty(wi->tess, GLU_TESS_BOUNDARY_ONLY, GL_TRUE); gluTessBeginPolygon(wi->tess, cv); - for (j = 0; j < poly->num_contours; j++){ - gluTessBeginContour(wi->tess); - for (i = 0; i < poly->contours[j].num_points; i++) { - v[0] = poly->contours[j].points[i].x; - v[1] = poly->contours[j].points[i].y; - v[2] = 0; - gluTessVertex(wi->tess, v, &poly->contours[j].points[i]); + + /* + * We need to take care of the final (after transformation) winding + * direction of the polygon in order to have the right tesselation + * taking place. + */ + if (!revert) { + for (j = 0; j < poly->num_contours; j++){ + gluTessBeginContour(wi->tess); + for (i = 0; i < poly->contours[j].num_points; i++) { + v[0] = poly->contours[j].points[i].x; + v[1] = poly->contours[j].points[i].y; + v[2] = 0; + gluTessVertex(wi->tess, v, &poly->contours[j].points[i]); + } + gluTessEndContour(wi->tess); + } + } + else { + for (j = 0; j < poly->num_contours; j++){ + gluTessBeginContour(wi->tess); + for (i = poly->contours[j].num_points-1; i >= 0; i--) { + v[0] = poly->contours[j].points[i].x; + v[1] = poly->contours[j].points[i].y; + v[2] = 0; + gluTessVertex(wi->tess, v, &poly->contours[j].points[i]); + } + gluTessEndContour(wi->tess); } - gluTessEndContour(wi->tess); } gluTessEndPolygon(wi->tess); cdata = wi->tess_combine_list; @@ -748,7 +794,7 @@ ComputeCoordinates(Item item, int lw; ZnContour *c1, *c2; ZnPoly dev; - + ZnBool revert; ResetBBox(&item->item_bounding_box); @@ -779,7 +825,6 @@ ComputeCoordinates(Item item, for (c1 = cv->shape.contours, c2 = dev.contours, i = 0; i < cv->shape.num_contours; i++, c1++, c2++) { - c2->cw = c1->cw; c2->num_points = c1->num_points; /* * Add a point at the end of the contour to close it @@ -841,7 +886,7 @@ ComputeCoordinates(Item item, } /* - * Replce the original path by the expanded, closing it as + * Replace the original path by the expanded, closing it as * needed (one open contour). */ num_points =ZnListSize(wi->work_pts); @@ -857,13 +902,39 @@ ComputeCoordinates(Item item, } } - UpdateTristrip(cv, &dev); + /* + * Test the scale factors to see if we need to reverse the + * polygons winding. + */ + revert = (wi->current_transfo->_[0][0]*wi->current_transfo->_[1][1]) < 0; if (num_contours == 1) { + if (cv->shape.contours[0].num_points > 2) { + UpdateTristrip(cv, &dev, revert); + /*if (!cv->tristrip.num_strips) { + int kk; + ZnPrintTransfo(wi->current_transfo); + printf("id: %d, NumCont: %d, NumPoints: %d, Original: %d, Resultat: %d, NumTri: %d\n", + item->id, num_contours,cv->shape.contours[0].num_points, + cv->shape.contours[0].cw, cw_dev_contour1, cv->tristrip.num_strips); + for (kk = 0; kk < cv->shape.contours[0].num_points; kk++) { + printf("%g@%g ", cv->shape.contours[0].points[kk].x, + cv->shape.contours[0].points[kk].y); + } + printf("\n"); + }*/ + } POLY_CONTOUR1(&cv->outlines, dev.contours[0].points, dev.contours[0].num_points, - dev.contours[0].cw); + cv->shape.contours[0].cw); } else { - UpdateOutlines(cv, &dev); + UpdateTristrip(cv, &dev, revert); + /*if (!cv->tristrip.num_strips) { + ZnPrintTransfo(wi->current_transfo); + printf("id: %d, NumCont: %d, NumPoints: %d, Original: %d, Resultat: %d, NumTri: %d\n", + item->id, num_contours,cv->shape.contours[0].num_points, + cv->shape.contours[0].cw, cw_dev_contour1, cv->tristrip.num_strips); + }*/ + UpdateOutlines(cv, &dev, revert); POLY_FREE(&dev); } @@ -1387,10 +1458,11 @@ Render(Item item) return; } +#ifdef GL_LIST if (!item->gl_list) { item->gl_list = glGenLists(1); glNewList(item->gl_list, GL_COMPILE); - +#endif /* * Fill if requested. */ @@ -1484,12 +1556,13 @@ Render(Item item) } } } - +#ifdef GL_LIST glEndList(); } glCallList(item->gl_list); #endif +#endif } |