Added Mesh::Combine and changed tempPointList to FTList
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
diff --git a/include/FTVectoriser.h b/include/FTVectoriser.h
index dc751bc..4223d1c 100644
--- a/include/FTVectoriser.h
+++ b/include/FTVectoriser.h
@@ -3,6 +3,7 @@
#include "FTContour.h"
+#include "FTList.h"
#include "FTPoint.h"
#include "FTVector.h"
#include "FTGL.h"
@@ -22,7 +23,8 @@ class FTGL_EXPORT FTTesselation
/**
* Default constructor
*/
- FTTesselation()
+ FTTesselation( GLenum m)
+ : meshType(m)
{
pointList.reserve( 128);
}
@@ -35,19 +37,27 @@ class FTGL_EXPORT FTTesselation
pointList.clear();
}
-
+ /**
+ * Add a point to the mesh.
+ */
void AddPoint( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUBLE z)
{
pointList.push_back( FTPoint( x, y, z));
}
-
+ /**
+ * The number of points in this mesh
+ */
size_t PointCount() const { return pointList.size();}
+ /**
+ *
+ */
const FTPoint& Point( unsigned int index) const { return pointList[index];}
-
- void PolygonType( GLenum m) { meshType = m;}
+ /**
+ * Return the OpenGL polygon type.
+ */
GLenum PolygonType() const { return meshType;}
private:
@@ -69,6 +79,9 @@ class FTGL_EXPORT FTTesselation
*/
class FTGL_EXPORT FTMesh
{
+ typedef FTVector<FTTesselation*> TesselationVector;
+ typedef FTList<FTPoint> PointList;
+
public:
/**
* Default constructor
@@ -80,28 +93,51 @@ class FTGL_EXPORT FTMesh
*/
~FTMesh();
+ /**
+ *
+ */
void AddPoint( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUBLE z);
- void Begin( GLenum m);
+
+ /**
+ *
+ */
+ FTGL_DOUBLE* Combine( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUBLE z);
+
+ /**
+ *
+ */
+ void Begin( GLenum meshType);
+
+ /**
+ *
+ */
void End();
+
+ /**
+ *
+ */
void Error( GLenum e) { err = e;}
+ /**
+ *
+ */
unsigned int TesselationCount() const { return tesselationList.size();}
+ /**
+ *
+ */
const FTTesselation* const Tesselation( unsigned int index) const;
+
+ /**
+ *
+ */
+ const PointList& TempPointList() const { return tempPointList;}
/**
* Get the GL ERROR returned by the glu tesselator
*/
GLenum Error() const { return err;}
- /**
- * Holds extra points created by gluTesselator. See ftglCombine.
- */
- typedef FTVector<FTPoint> PointVector;
- PointVector tempPointList;
-
- protected:
-
private:
/**
* The current sub mesh that we are constructing.
@@ -111,10 +147,14 @@ class FTGL_EXPORT FTMesh
/**
* Holds each sub mesh that comprises this glyph.
*/
- typedef FTVector<FTTesselation*> TesselationVector;
TesselationVector tesselationList;
/**
+ * Holds extra points created by gluTesselator. See ftglCombine.
+ */
+ PointList tempPointList;
+
+ /**
* GL ERROR returned by the glu tesselator
*/
GLenum err;
diff --git a/src/FTVectoriser.cpp b/src/FTVectoriser.cpp
index 982cd9e..02c6a08 100644
--- a/src/FTVectoriser.cpp
+++ b/src/FTVectoriser.cpp
@@ -22,13 +22,21 @@ void CALLBACK ftglError( GLenum errCode, FTMesh* mesh)
mesh->Error( errCode);
}
+
void CALLBACK ftglVertex( void* data, FTMesh* mesh)
{
- FTGL_DOUBLE* vertex = (FTGL_DOUBLE*)data;
+ FTGL_DOUBLE* vertex = static_cast<FTGL_DOUBLE*>(data);
mesh->AddPoint( vertex[0], vertex[1], vertex[2]);
}
+void CALLBACK ftglCombine( FTGL_DOUBLE coords[3], void* vertex_data[4], GLfloat weight[4], void** outData, FTMesh* mesh)
+{
+ FTGL_DOUBLE* vertex = static_cast<FTGL_DOUBLE*>(coords);
+ *outData = mesh->Combine( vertex[0], vertex[1], vertex[2]);
+}
+
+
void CALLBACK ftglBegin( GLenum type, FTMesh* mesh)
{
mesh->Begin( type);
@@ -41,22 +49,11 @@ void CALLBACK ftglEnd( FTMesh* mesh)
}
-void CALLBACK ftglCombine( FTGL_DOUBLE coords[3], void* vertex_data[4], GLfloat weight[4], void** outData, FTMesh* mesh)
-{
- FTGL_DOUBLE* vertex = (FTGL_DOUBLE*)coords;
- mesh->tempPointList.push_back( FTPoint( vertex[0], vertex[1], vertex[2]));
-
- // FIXME if tempPointList reallocs we'll loose these. replace it with a list.
- *outData = &mesh->tempPointList[ mesh->tempPointList.size() - 1].x;
-}
-
-
FTMesh::FTMesh()
: currentTesselation(0),
err(0)
{
tesselationList.reserve( 16);
- tempPointList.reserve( 128);
}
@@ -67,8 +64,6 @@ FTMesh::~FTMesh()
delete tesselationList[t];
}
tesselationList.clear();
-
- tempPointList.clear();
}
@@ -77,10 +72,17 @@ void FTMesh::AddPoint( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUB
currentTesselation->AddPoint( x, y, z);
}
-void FTMesh::Begin( GLenum m)
+
+FTGL_DOUBLE* FTMesh::Combine( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUBLE z)
{
- currentTesselation = new FTTesselation;
- currentTesselation->PolygonType( m);
+ tempPointList.push_back( FTPoint( x, y,z));
+ return &tempPointList.back().x;
+}
+
+
+void FTMesh::Begin( GLenum meshType)
+{
+ currentTesselation = new FTTesselation( meshType);
}
@@ -95,6 +97,7 @@ const FTTesselation* const FTMesh::Tesselation( unsigned int index) const
return ( index < tesselationList.size()) ? tesselationList[index] : NULL;
}
+
FTVectoriser::FTVectoriser( const FT_Glyph glyph)
: contourList(0),
mesh(0),
diff --git a/test/FTTesselation-Test.cpp b/test/FTTesselation-Test.cpp
index 1c665cf..a7fc85d 100755
--- a/test/FTTesselation-Test.cpp
+++ b/test/FTTesselation-Test.cpp
@@ -22,7 +22,7 @@ class FTTesselationTest : public CppUnit::TestCase
void testAddPoint()
{
- FTTesselation tesselation;
+ FTTesselation tesselation( 1);
CPPUNIT_ASSERT( tesselation.PointCount() == 0);
@@ -44,7 +44,7 @@ class FTTesselationTest : public CppUnit::TestCase
void testGetPoint()
{
- FTTesselation tesselation;
+ FTTesselation tesselation(1);
CPPUNIT_ASSERT( tesselation.PointCount() == 0);