Added Winding fuction to colc area for a full contour rather than part of one
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
diff --git a/include/FTExtrdGlyph.h b/include/FTExtrdGlyph.h
index 014be4e..ac394d9 100644
--- a/include/FTExtrdGlyph.h
+++ b/include/FTExtrdGlyph.h
@@ -44,11 +44,12 @@ class FTGL_EXPORT FTExtrdGlyph : public FTGlyph
private:
/**
- * Convert the point data into a mesh.
+ * Calculate the winding direction of a contour.
*
- * Uses GLUtesselator to create a mesh
+ * This uses the signed area of the contour. It is required because
+ * freetype doesn't do this despite the docs saying it does:(
*/
- void Tesselate();
+ bool Winding( int numPoints, double *points);
/**
* An object that helps convert freetype outlines into point
diff --git a/src/FTExtrdGlyph.cpp b/src/FTExtrdGlyph.cpp
index 38a8efd..17cd44a 100644
--- a/src/FTExtrdGlyph.cpp
+++ b/src/FTExtrdGlyph.cpp
@@ -1,9 +1,11 @@
+#ifdef FTGL_DEBUG
+ #include "mmgr.h"
+#endif
+
#include "FTExtrdGlyph.h"
#include "FTVectoriser.h"
-//#include "mmgr.h"
-
FTExtrdGlyph::FTExtrdGlyph( FT_Glyph glyph, float d)
: FTGlyph(),
vectoriser(0),
@@ -121,35 +123,22 @@ FTExtrdGlyph::FTExtrdGlyph( FT_Glyph glyph, float d)
FT_OutlineGlyph outline = (FT_OutlineGlyph)glyph;
FT_Outline ftOutline = outline->outline;
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;
-
+ // This assumes that the first contour is an outside contour!!!
+ bool winding = Winding( contourLength[0], sidemesh);
+
// Join them together.
// Extrude each contour to make the sides.
double* contour = sidemesh;
for (int c=0; c<numContours; ++c)
{
-
// Make a quad strip using each successive
// pair of points in this contour.
int numPoints = contourLength[c];
- glBegin(GL_QUAD_STRIP);
+
+ glBegin( GL_QUAD_STRIP);
- for (int j= 0; j <= numPoints; ++j)
+ for( int j= 0; j <= numPoints; ++j)
{
int j1 = (j < numPoints) ? j : 0;
int j0 = (j1 == 0) ? (numPoints-1) : (j1-1);
@@ -166,7 +155,7 @@ FTExtrdGlyph::FTExtrdGlyph( FT_Glyph glyph, float d)
glNormal3d(-vy, vx, 0.0);
// Add vertices to the quad strip.
- // Winding order!!!
+ // Winding order
// if( contourFlag & ft_outline_reverse_fill) // this is broken in freetype so...
if( winding)
{
@@ -203,6 +192,25 @@ FTExtrdGlyph::~FTExtrdGlyph()
}
+bool FTExtrdGlyph::Winding( int numPoints, double *points)
+{
+ // Calculate the winding direction. use formula from redbook.
+ double area = 0;
+
+ for( int count= 0; count <= numPoints; ++count)
+ {
+ int j1 = (count < numPoints) ? count : 0;
+ int j0 = (j1 == 0) ? ( numPoints-1) : ( j1-1);
+
+ double* p0 = points + j0 * 3;
+ double* p1 = points + j1 * 3;
+
+ area += ( p0[0] * p1[1]) - ( p1[0] * p0[1]);
+ }
+
+ return( area < 0 ? false: true);
+}
+
float FTExtrdGlyph::Render( const FT_Vector& pen)
{
if( glList)