| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> |
| <title>FTGL: FTVectoriser.cpp Source File</title> |
| <link href="doxygen.css" rel="stylesheet" type="text/css"> |
| </head><body> |
| <!-- Generated by Doxygen 1.3.6 --> |
| <div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a></div> |
| <h1>FTVectoriser.cpp</h1><a href="FTVectoriser_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="preprocessor">#include "<a class="code" href="FTVectoriser_8h.html">FTVectoriser.h</a>"</span> |
| 00002 <span class="preprocessor">#include "<a class="code" href="FTGL_8h.html">FTGL.h</a>"</span> |
| 00003 |
| 00004 <span class="preprocessor">#ifndef CALLBACK</span> |
| 00005 <span class="preprocessor"></span><span class="preprocessor">#define CALLBACK</span> |
| 00006 <span class="preprocessor"></span><span class="preprocessor">#endif</span> |
| 00007 <span class="preprocessor"></span> |
| 00008 <span class="preprocessor">#ifdef __APPLE_CC__ </span> |
| 00009 <span class="preprocessor"></span> <span class="keyword">typedef</span> GLvoid (*GLUTesselatorFunction)(...); |
| 00010 <span class="preprocessor">#elif defined( __mips ) || defined( __linux__ ) || defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __sun ) || defined (__CYGWIN__)</span> |
| 00011 <span class="preprocessor"></span> <span class="keyword">typedef</span> GLvoid (*GLUTesselatorFunction)(); |
| 00012 <span class="preprocessor">#elif defined ( WIN32)</span> |
| 00013 <span class="preprocessor"></span> <span class="keyword">typedef</span> GLvoid (CALLBACK *GLUTesselatorFunction)( ); |
| 00014 <span class="preprocessor">#else</span> |
| 00015 <span class="preprocessor"></span><span class="preprocessor"> #error "Error - need to define type GLUTesselatorFunction for this platform/compiler"</span> |
| 00016 <span class="preprocessor"></span><span class="preprocessor">#endif</span> |
| 00017 <span class="preprocessor"></span> |
| 00018 |
| <a name="l00019"></a><a class="code" href="FTVectoriser_8cpp.html#a0">00019</a> <span class="keywordtype">void</span> CALLBACK <a class="code" href="FTVectoriser_8cpp.html#a0">ftglError</a>( GLenum errCode, <a class="code" href="classFTMesh.html">FTMesh</a>* mesh) |
| 00020 { |
| 00021 mesh-><a class="code" href="classFTMesh.html#a6">Error</a>( errCode); |
| 00022 } |
| 00023 |
| 00024 |
| <a name="l00025"></a><a class="code" href="FTVectoriser_8cpp.html#a1">00025</a> <span class="keywordtype">void</span> CALLBACK <a class="code" href="FTVectoriser_8cpp.html#a1">ftglVertex</a>( <span class="keywordtype">void</span>* data, <a class="code" href="classFTMesh.html">FTMesh</a>* mesh) |
| 00026 { |
| 00027 <a class="code" href="FTGL_8h.html#a4">FTGL_DOUBLE</a>* vertex = static_cast<FTGL_DOUBLE*>(data); |
| 00028 mesh-><a class="code" href="classFTMesh.html#a2">AddPoint</a>( vertex[0], vertex[1], vertex[2]); |
| 00029 } |
| 00030 |
| 00031 |
| <a name="l00032"></a><a class="code" href="FTVectoriser_8cpp.html#a2">00032</a> <span class="keywordtype">void</span> CALLBACK <a class="code" href="FTVectoriser_8cpp.html#a2">ftglCombine</a>( <a class="code" href="FTGL_8h.html#a4">FTGL_DOUBLE</a> coords[3], <span class="keywordtype">void</span>* vertex_data[4], GLfloat weight[4], <span class="keywordtype">void</span>** outData, <a class="code" href="classFTMesh.html">FTMesh</a>* mesh) |
| 00033 { |
| 00034 <a class="code" href="FTGL_8h.html#a4">FTGL_DOUBLE</a>* vertex = static_cast<FTGL_DOUBLE*>(coords); |
| 00035 *outData = mesh-><a class="code" href="classFTMesh.html#a3">Combine</a>( vertex[0], vertex[1], vertex[2]); |
| 00036 } |
| 00037 |
| 00038 |
| <a name="l00039"></a><a class="code" href="FTVectoriser_8cpp.html#a3">00039</a> <span class="keywordtype">void</span> CALLBACK <a class="code" href="FTVectoriser_8cpp.html#a3">ftglBegin</a>( GLenum type, <a class="code" href="classFTMesh.html">FTMesh</a>* mesh) |
| 00040 { |
| 00041 mesh-><a class="code" href="classFTMesh.html#a4">Begin</a>( type); |
| 00042 } |
| 00043 |
| 00044 |
| <a name="l00045"></a><a class="code" href="FTVectoriser_8cpp.html#a4">00045</a> <span class="keywordtype">void</span> CALLBACK <a class="code" href="FTVectoriser_8cpp.html#a4">ftglEnd</a>( <a class="code" href="classFTMesh.html">FTMesh</a>* mesh) |
| 00046 { |
| 00047 mesh-><a class="code" href="classFTMesh.html#a5">End</a>(); |
| 00048 } |
| 00049 |
| 00050 |
| <a name="l00051"></a><a class="code" href="classFTMesh.html#a0">00051</a> <a class="code" href="classFTMesh.html#a0">FTMesh::FTMesh</a>() |
| 00052 : currentTesselation(0), |
| 00053 err(0) |
| 00054 { |
| 00055 tesselationList.<a class="code" href="classFTVector.html#a13">reserve</a>( 16); |
| 00056 } |
| 00057 |
| 00058 |
| <a name="l00059"></a><a class="code" href="classFTMesh.html#a1">00059</a> <a class="code" href="classFTMesh.html#a1">FTMesh::~FTMesh</a>() |
| 00060 { |
| 00061 <span class="keywordflow">for</span>( size_t t = 0; t < tesselationList.<a class="code" href="classFTVector.html#a3">size</a>(); ++t) |
| 00062 { |
| 00063 <span class="keyword">delete</span> tesselationList[t]; |
| 00064 } |
| 00065 |
| 00066 tesselationList.<a class="code" href="classFTVector.html#a12">clear</a>(); |
| 00067 } |
| 00068 |
| 00069 |
| <a name="l00070"></a><a class="code" href="classFTMesh.html#a2">00070</a> <span class="keywordtype">void</span> <a class="code" href="classFTMesh.html#a2">FTMesh::AddPoint</a>( <span class="keyword">const</span> <a class="code" href="FTGL_8h.html#a4">FTGL_DOUBLE</a> x, <span class="keyword">const</span> <a class="code" href="FTGL_8h.html#a4">FTGL_DOUBLE</a> y, <span class="keyword">const</span> <a class="code" href="FTGL_8h.html#a4">FTGL_DOUBLE</a> z) |
| 00071 { |
| 00072 currentTesselation-><a class="code" href="classFTTesselation.html#a2">AddPoint</a>( x, y, z); |
| 00073 } |
| 00074 |
| 00075 |
| <a name="l00076"></a><a class="code" href="classFTMesh.html#a3">00076</a> <a class="code" href="FTGL_8h.html#a4">FTGL_DOUBLE</a>* <a class="code" href="classFTMesh.html#a3">FTMesh::Combine</a>( <span class="keyword">const</span> <a class="code" href="FTGL_8h.html#a4">FTGL_DOUBLE</a> x, <span class="keyword">const</span> <a class="code" href="FTGL_8h.html#a4">FTGL_DOUBLE</a> y, <span class="keyword">const</span> <a class="code" href="FTGL_8h.html#a4">FTGL_DOUBLE</a> z) |
| 00077 { |
| 00078 tempPointList.<a class="code" href="classFTList.html#a3">push_back</a>( <a class="code" href="classFTPoint.html">FTPoint</a>( x, y,z)); |
| 00079 <span class="keywordflow">return</span> static_cast<FTGL_DOUBLE*>(tempPointList.<a class="code" href="classFTList.html#a5">back</a>()); |
| 00080 } |
| 00081 |
| 00082 |
| <a name="l00083"></a><a class="code" href="classFTMesh.html#a4">00083</a> <span class="keywordtype">void</span> <a class="code" href="classFTMesh.html#a4">FTMesh::Begin</a>( GLenum meshType) |
| 00084 { |
| 00085 currentTesselation = <span class="keyword">new</span> <a class="code" href="classFTTesselation.html">FTTesselation</a>( meshType); |
| 00086 } |
| 00087 |
| 00088 |
| <a name="l00089"></a><a class="code" href="classFTMesh.html#a5">00089</a> <span class="keywordtype">void</span> <a class="code" href="classFTMesh.html#a5">FTMesh::End</a>() |
| 00090 { |
| 00091 tesselationList.<a class="code" href="classFTVector.html#a14">push_back</a>( currentTesselation); |
| 00092 } |
| 00093 |
| 00094 |
| <a name="l00095"></a><a class="code" href="classFTMesh.html#a8">00095</a> <span class="keyword">const</span> <a class="code" href="classFTTesselation.html">FTTesselation</a>* <span class="keyword">const</span> <a class="code" href="classFTMesh.html#a8">FTMesh::Tesselation</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> index)<span class="keyword"> const</span> |
| 00096 <span class="keyword"></span>{ |
| 00097 <span class="keywordflow">return</span> ( index < tesselationList.<a class="code" href="classFTVector.html#a3">size</a>()) ? tesselationList[index] : NULL; |
| 00098 } |
| 00099 |
| 00100 |
| <a name="l00101"></a><a class="code" href="classFTVectoriser.html#a0">00101</a> <a class="code" href="classFTVectoriser.html#a0">FTVectoriser::FTVectoriser</a>( <span class="keyword">const</span> FT_GlyphSlot glyph) |
| 00102 : contourList(0), |
| 00103 mesh(0), |
| 00104 ftContourCount(0), |
| 00105 contourFlag(0) |
| 00106 { |
| 00107 <span class="keywordflow">if</span>( glyph) |
| 00108 { |
| 00109 outline = glyph->outline; |
| 00110 |
| 00111 ftContourCount = outline.n_contours; |
| 00112 contourList = 0; |
| 00113 contourFlag = outline.flags; |
| 00114 |
| 00115 ProcessContours(); |
| 00116 } |
| 00117 } |
| 00118 |
| 00119 |
| <a name="l00120"></a><a class="code" href="classFTVectoriser.html#a1">00120</a> <a class="code" href="classFTVectoriser.html#a1">FTVectoriser::~FTVectoriser</a>() |
| 00121 { |
| 00122 <span class="keywordflow">for</span>( size_t c = 0; c < <a class="code" href="classFTVectoriser.html#a5">ContourCount</a>(); ++c) |
| 00123 { |
| 00124 <span class="keyword">delete</span> contourList[c]; |
| 00125 } |
| 00126 |
| 00127 <span class="keyword">delete</span> [] contourList; |
| 00128 <span class="keyword">delete</span> mesh; |
| 00129 } |
| 00130 |
| 00131 |
| 00132 <span class="keywordtype">void</span> FTVectoriser::ProcessContours() |
| 00133 { |
| 00134 <span class="keywordtype">short</span> contourLength = 0; |
| 00135 <span class="keywordtype">short</span> startIndex = 0; |
| 00136 <span class="keywordtype">short</span> endIndex = 0; |
| 00137 |
| 00138 contourList = <span class="keyword">new</span> <a class="code" href="classFTContour.html">FTContour</a>*[ftContourCount]; |
| 00139 |
| 00140 <span class="keywordflow">for</span>( <span class="keywordtype">short</span> contourIndex = 0; contourIndex < ftContourCount; ++contourIndex) |
| 00141 { |
| 00142 FT_Vector* pointList = &outline.points[startIndex]; |
| 00143 <span class="keywordtype">char</span>* tagList = &outline.tags[startIndex]; |
| 00144 |
| 00145 endIndex = outline.contours[contourIndex]; |
| 00146 contourLength = ( endIndex - startIndex) + 1; |
| 00147 |
| 00148 FTContour* contour = <span class="keyword">new</span> FTContour( pointList, tagList, contourLength); |
| 00149 |
| 00150 contourList[contourIndex] = contour; |
| 00151 |
| 00152 startIndex = endIndex + 1; |
| 00153 } |
| 00154 } |
| 00155 |
| 00156 |
| <a name="l00157"></a><a class="code" href="classFTVectoriser.html#a4">00157</a> size_t <a class="code" href="classFTVectoriser.html#a4">FTVectoriser::PointCount</a>() |
| 00158 { |
| 00159 size_t s = 0; |
| 00160 <span class="keywordflow">for</span>( size_t c = 0; c < <a class="code" href="classFTVectoriser.html#a5">ContourCount</a>(); ++c) |
| 00161 { |
| 00162 s += contourList[c]-><a class="code" href="classFTContour.html#a3">PointCount</a>(); |
| 00163 } |
| 00164 |
| 00165 <span class="keywordflow">return</span> s; |
| 00166 } |
| 00167 |
| 00168 |
| <a name="l00169"></a><a class="code" href="classFTVectoriser.html#a6">00169</a> <span class="keyword">const</span> <a class="code" href="classFTContour.html">FTContour</a>* <span class="keyword">const</span> <a class="code" href="classFTVectoriser.html#a6">FTVectoriser::Contour</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> index)<span class="keyword"> const</span> |
| 00170 <span class="keyword"></span>{ |
| 00171 <span class="keywordflow">return</span> ( index < <a class="code" href="classFTVectoriser.html#a5">ContourCount</a>()) ? contourList[index] : NULL; |
| 00172 } |
| 00173 |
| 00174 |
| <a name="l00175"></a><a class="code" href="classFTVectoriser.html#a2">00175</a> <span class="keywordtype">void</span> <a class="code" href="classFTVectoriser.html#a2">FTVectoriser::MakeMesh</a>( <a class="code" href="FTGL_8h.html#a4">FTGL_DOUBLE</a> zNormal) |
| 00176 { |
| 00177 <span class="keywordflow">if</span>( mesh) |
| 00178 { |
| 00179 <span class="keyword">delete</span> mesh; |
| 00180 } |
| 00181 |
| 00182 mesh = <span class="keyword">new</span> <a class="code" href="classFTMesh.html">FTMesh</a>; |
| 00183 |
| 00184 GLUtesselator* tobj = gluNewTess(); |
| 00185 |
| 00186 gluTessCallback( tobj, GLU_TESS_BEGIN_DATA, (GLUTesselatorFunction)<a class="code" href="FTVectoriser_8cpp.html#a3">ftglBegin</a>); |
| 00187 gluTessCallback( tobj, GLU_TESS_VERTEX_DATA, (GLUTesselatorFunction)<a class="code" href="FTVectoriser_8cpp.html#a1">ftglVertex</a>); |
| 00188 gluTessCallback( tobj, GLU_TESS_COMBINE_DATA, (GLUTesselatorFunction)<a class="code" href="FTVectoriser_8cpp.html#a2">ftglCombine</a>); |
| 00189 gluTessCallback( tobj, GLU_TESS_END_DATA, (GLUTesselatorFunction)<a class="code" href="FTVectoriser_8cpp.html#a4">ftglEnd</a>); |
| 00190 gluTessCallback( tobj, GLU_TESS_ERROR_DATA, (GLUTesselatorFunction)<a class="code" href="FTVectoriser_8cpp.html#a0">ftglError</a>); |
| 00191 |
| 00192 <span class="keywordflow">if</span>( contourFlag & ft_outline_even_odd_fill) <span class="comment">// ft_outline_reverse_fill</span> |
| 00193 { |
| 00194 gluTessProperty( tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD); |
| 00195 } |
| 00196 <span class="keywordflow">else</span> |
| 00197 { |
| 00198 gluTessProperty( tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO); |
| 00199 } |
| 00200 |
| 00201 |
| 00202 gluTessProperty( tobj, GLU_TESS_TOLERANCE, 0); |
| 00203 gluTessNormal( tobj, 0.0f, 0.0f, zNormal); |
| 00204 gluTessBeginPolygon( tobj, mesh); |
| 00205 |
| 00206 <span class="keywordflow">for</span>( size_t c = 0; c < <a class="code" href="classFTVectoriser.html#a5">ContourCount</a>(); ++c) |
| 00207 { |
| 00208 <span class="keyword">const</span> <a class="code" href="classFTContour.html">FTContour</a>* contour = contourList[c]; |
| 00209 |
| 00210 gluTessBeginContour( tobj); |
| 00211 |
| 00212 <span class="keywordflow">for</span>( size_t p = 0; p < contour-><a class="code" href="classFTContour.html#a3">PointCount</a>(); ++p) |
| 00213 { |
| 00214 <a class="code" href="FTGL_8h.html#a4">FTGL_DOUBLE</a>* d = (<a class="code" href="FTGL_8h.html#a4">FTGL_DOUBLE</a>*)(contour-><a class="code" href="classFTContour.html#a2">Point</a>(p)); <span class="comment">// FIXME use c++ cast</span> |
| 00215 gluTessVertex( tobj, d, d); |
| 00216 } |
| 00217 |
| 00218 gluTessEndContour( tobj); |
| 00219 } |
| 00220 |
| 00221 gluTessEndPolygon( tobj); |
| 00222 |
| 00223 gluDeleteTess( tobj); |
| 00224 } |
| 00225 |
| </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Dec 5 22:24:06 2004 for FTGL by |
| <a href="http://www.doxygen.org/index.html"> |
| <img src="doxygen.png" alt="doxygen" align="middle" border=0 > |
| </a>1.3.6 </small></address> |
| </body> |
| </html> |