Added a work around for a bug in freetype. Calcs the winding direction of the contour
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/src/FTExtrdGlyph.cpp b/src/FTExtrdGlyph.cpp
index 3eaa1d7..38a8efd 100644
--- a/src/FTExtrdGlyph.cpp
+++ b/src/FTExtrdGlyph.cpp
@@ -120,7 +120,23 @@ FTExtrdGlyph::FTExtrdGlyph( FT_Glyph glyph, float d)
FT_OutlineGlyph outline = (FT_OutlineGlyph)glyph;
FT_Outline ftOutline = outline->outline;
- int contourFlag = ftOutline.flags;
+ int contourFlag = ftOutline.flags; // this is broken for winding direction in freetype so...
+ // Calculate the winding direction. use formula from redbook.
+ double x1 = *( sidemesh);
+ double x2 = *( sidemesh + 1);
+ double x3 = *( sidemesh + 2);
+ double y1 = *( sidemesh + 3);
+ double y2 = *( sidemesh + 4);
+ double y3 = *( sidemesh + 5);
+
+ double a1 = ( x1 * y2) - ( x2 * y1);
+ double a2 = ( x2 * y3) - ( x3 * y2);
+ double a3 = ( x3 * y1) - ( x1 * y3);
+
+ double a = ( a1 + a2 + a3) / 2;
+
+ bool winding = a < 0 ? false: true;
+
// Join them together.
// Extrude each contour to make the sides.
@@ -151,7 +167,8 @@ FTExtrdGlyph::FTExtrdGlyph( FT_Glyph glyph, float d)
// Add vertices to the quad strip.
// Winding order!!!
- if( contourFlag & ft_outline_reverse_fill)
+// if( contourFlag & ft_outline_reverse_fill) // this is broken in freetype so...
+ if( winding)
{
glVertex3d(p0[0], p0[1], 0);
glVertex3d(p0[0], p0[1], -depth);