blob: 6485dafd3d92ea5eff8607a61981b24543adef67 [file] [log] [blame]
<!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: FTExtrdGlyph.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&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a></div>
<h1>FTExtrdGlyph.cpp</h1><a href="FTExtrdGlyph_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="preprocessor">#include &lt;iostream&gt;</span>
00002
00003 <span class="preprocessor">#include &lt;math.h&gt;</span>
00004
00005 <span class="preprocessor">#include "<a class="code" href="FTExtrdGlyph_8h.html">FTExtrdGlyph.h</a>"</span>
00006 <span class="preprocessor">#include "<a class="code" href="FTVectoriser_8h.html">FTVectoriser.h</a>"</span>
00007
00008
<a name="l00009"></a><a class="code" href="classFTExtrdGlyph.html#a0">00009</a> <a class="code" href="classFTExtrdGlyph.html#a0">FTExtrdGlyph::FTExtrdGlyph</a>( FT_GlyphSlot glyph, <span class="keywordtype">float</span> depth, <span class="keywordtype">bool</span> useDisplayList)
00010 : <a class="code" href="classFTGlyph.html">FTGlyph</a>( glyph),
00011 glList(0)
00012 {
00013 bBox.<a class="code" href="classFTBBox.html#a6">SetDepth</a>( -depth);
00014
00015 <span class="keywordflow">if</span>( ft_glyph_format_outline != glyph-&gt;format)
00016 {
00017 err = 0x14; <span class="comment">// Invalid_Outline</span>
00018 <span class="keywordflow">return</span>;
00019 }
00020
00021 <a class="code" href="classFTVectoriser.html">FTVectoriser</a> vectoriser( glyph);
00022 <span class="keywordflow">if</span>( ( vectoriser.<a class="code" href="classFTVectoriser.html#a5">ContourCount</a>() &lt; 1) || ( vectoriser.<a class="code" href="classFTVectoriser.html#a4">PointCount</a>() &lt; 3))
00023 {
00024 <span class="keywordflow">return</span>;
00025 }
00026
00027 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> tesselationIndex;
00028
00029 <span class="keywordflow">if</span>(useDisplayList)
00030 {
00031 glList = glGenLists(1);
00032 glNewList( glList, GL_COMPILE);
00033 }
00034
00035 vectoriser.<a class="code" href="classFTVectoriser.html#a2">MakeMesh</a>( 1.0);
00036 glNormal3d(0.0, 0.0, 1.0);
00037
00038 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> horizontalTextureScale = glyph-&gt;face-&gt;size-&gt;metrics.x_ppem * 64;
00039 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> verticalTextureScale = glyph-&gt;face-&gt;size-&gt;metrics.y_ppem * 64;
00040
00041 <span class="keyword">const</span> <a class="code" href="classFTMesh.html">FTMesh</a>* mesh = vectoriser.<a class="code" href="classFTVectoriser.html#a3">GetMesh</a>();
00042 <span class="keywordflow">for</span>( tesselationIndex = 0; tesselationIndex &lt; mesh-&gt;<a class="code" href="classFTMesh.html#a7">TesselationCount</a>(); ++tesselationIndex)
00043 {
00044 <span class="keyword">const</span> <a class="code" href="classFTTesselation.html">FTTesselation</a>* subMesh = mesh-&gt;<a class="code" href="classFTMesh.html#a8">Tesselation</a>( tesselationIndex);
00045 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> polyonType = subMesh-&gt;<a class="code" href="classFTTesselation.html#a5">PolygonType</a>();
00046
00047 glBegin( polyonType);
00048 <span class="keywordflow">for</span>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> pointIndex = 0; pointIndex &lt; subMesh-&gt;<a class="code" href="classFTTesselation.html#a3">PointCount</a>(); ++pointIndex)
00049 {
00050 <a class="code" href="classFTPoint.html">FTPoint</a> point = subMesh-&gt;<a class="code" href="classFTTesselation.html#a4">Point</a>(pointIndex);
00051
00052 glTexCoord2f( point.<a class="code" href="classFTPoint.html#a7">X</a>() / horizontalTextureScale,
00053 point.<a class="code" href="classFTPoint.html#a8">Y</a>() / verticalTextureScale);
00054
00055 glVertex3f( point.<a class="code" href="classFTPoint.html#a7">X</a>() / 64.0f,
00056 point.<a class="code" href="classFTPoint.html#a8">Y</a>() / 64.0f,
00057 0.0f);
00058 }
00059 glEnd();
00060 }
00061
00062 vectoriser.<a class="code" href="classFTVectoriser.html#a2">MakeMesh</a>( -1.0);
00063 glNormal3d(0.0, 0.0, -1.0);
00064
00065 mesh = vectoriser.<a class="code" href="classFTVectoriser.html#a3">GetMesh</a>();
00066 <span class="keywordflow">for</span>( tesselationIndex = 0; tesselationIndex &lt; mesh-&gt;<a class="code" href="classFTMesh.html#a7">TesselationCount</a>(); ++tesselationIndex)
00067 {
00068 <span class="keyword">const</span> <a class="code" href="classFTTesselation.html">FTTesselation</a>* subMesh = mesh-&gt;<a class="code" href="classFTMesh.html#a8">Tesselation</a>( tesselationIndex);
00069 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> polyonType = subMesh-&gt;<a class="code" href="classFTTesselation.html#a5">PolygonType</a>();
00070
00071 glBegin( polyonType);
00072 <span class="keywordflow">for</span>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> pointIndex = 0; pointIndex &lt; subMesh-&gt;<a class="code" href="classFTTesselation.html#a3">PointCount</a>(); ++pointIndex)
00073 {
00074 <a class="code" href="classFTPoint.html">FTPoint</a> point = subMesh-&gt;<a class="code" href="classFTTesselation.html#a4">Point</a>(pointIndex);
00075
00076 glTexCoord2f( subMesh-&gt;<a class="code" href="classFTTesselation.html#a4">Point</a>(pointIndex).<a class="code" href="classFTPoint.html#a7">X</a>() / horizontalTextureScale,
00077 subMesh-&gt;<a class="code" href="classFTTesselation.html#a4">Point</a>(pointIndex).<a class="code" href="classFTPoint.html#a8">Y</a>() / verticalTextureScale);
00078
00079 glVertex3f( subMesh-&gt;<a class="code" href="classFTTesselation.html#a4">Point</a>( pointIndex).<a class="code" href="classFTPoint.html#a7">X</a>() / 64.0f,
00080 subMesh-&gt;<a class="code" href="classFTTesselation.html#a4">Point</a>( pointIndex).<a class="code" href="classFTPoint.html#a8">Y</a>() / 64.0f,
00081 -depth);
00082 }
00083 glEnd();
00084 }
00085
00086 <span class="keywordtype">int</span> contourFlag = vectoriser.<a class="code" href="classFTVectoriser.html#a8">ContourFlag</a>();
00087
00088 <span class="keywordflow">for</span>( size_t c = 0; c &lt; vectoriser.<a class="code" href="classFTVectoriser.html#a5">ContourCount</a>(); ++c)
00089 {
00090 <span class="keyword">const</span> <a class="code" href="classFTContour.html">FTContour</a>* contour = vectoriser.<a class="code" href="classFTVectoriser.html#a6">Contour</a>(c);
00091 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> numberOfPoints = contour-&gt;<a class="code" href="classFTContour.html#a3">PointCount</a>();
00092
00093 glBegin( GL_QUAD_STRIP);
00094 <span class="keywordflow">for</span>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> j = 0; j &lt;= numberOfPoints; ++j)
00095 {
00096 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> pointIndex = ( j == numberOfPoints) ? 0 : j;
00097 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nextPointIndex = ( pointIndex == numberOfPoints - 1) ? 0 : pointIndex + 1;
00098
00099 <a class="code" href="classFTPoint.html">FTPoint</a> point = contour-&gt;<a class="code" href="classFTContour.html#a2">Point</a>(pointIndex);
00100
00101 <a class="code" href="classFTPoint.html">FTPoint</a> normal = GetNormal( point, contour-&gt;<a class="code" href="classFTContour.html#a2">Point</a>(nextPointIndex));
00102 <span class="keywordflow">if</span>(normal != <a class="code" href="classFTPoint.html">FTPoint</a>( 0.0f, 0.0f, 0.0f))
00103 {
00104 glNormal3dv((<a class="code" href="FTGL_8h.html#a4">FTGL_DOUBLE</a>*)normal);
00105 }
00106
00107 <span class="keywordflow">if</span>( contourFlag &amp; ft_outline_reverse_fill)
00108 {
00109 glTexCoord2f( point.<a class="code" href="classFTPoint.html#a7">X</a>() / horizontalTextureScale,
00110 point.<a class="code" href="classFTPoint.html#a7">X</a>() / verticalTextureScale);
00111
00112 glVertex3f( point.<a class="code" href="classFTPoint.html#a7">X</a>() / 64.0f, point.<a class="code" href="classFTPoint.html#a8">Y</a>() / 64.0f, 0.0f);
00113 glVertex3f( point.<a class="code" href="classFTPoint.html#a7">X</a>() / 64.0f, point.<a class="code" href="classFTPoint.html#a8">Y</a>() / 64.0f, -depth);
00114 }
00115 <span class="keywordflow">else</span>
00116 {
00117 glTexCoord2f( point.<a class="code" href="classFTPoint.html#a7">X</a>() / horizontalTextureScale,
00118 point.<a class="code" href="classFTPoint.html#a8">Y</a>() / verticalTextureScale);
00119
00120 glVertex3f( point.<a class="code" href="classFTPoint.html#a7">X</a>() / 64.0f, point.<a class="code" href="classFTPoint.html#a8">Y</a>() / 64.0f, -depth);
00121 glVertex3f( point.<a class="code" href="classFTPoint.html#a7">X</a>() / 64.0f, point.<a class="code" href="classFTPoint.html#a8">Y</a>() / 64.0f, 0.0f);
00122 }
00123 }
00124 glEnd();
00125 }
00126
00127 <span class="keywordflow">if</span>(useDisplayList)
00128 {
00129 glEndList();
00130 }
00131 }
00132
00133
<a name="l00134"></a><a class="code" href="classFTExtrdGlyph.html#a1">00134</a> <a class="code" href="classFTExtrdGlyph.html#a1">FTExtrdGlyph::~FTExtrdGlyph</a>()
00135 {
00136 glDeleteLists( glList, 1);
00137 }
00138
00139
<a name="l00140"></a><a class="code" href="classFTExtrdGlyph.html#a2">00140</a> <span class="keyword">const</span> <a class="code" href="classFTPoint.html">FTPoint</a>&amp; <a class="code" href="classFTExtrdGlyph.html#a2">FTExtrdGlyph::Render</a>( <span class="keyword">const</span> <a class="code" href="classFTPoint.html">FTPoint</a>&amp; pen)
00141 {
00142 glTranslatef( pen.<a class="code" href="classFTPoint.html#a7">X</a>(), pen.<a class="code" href="classFTPoint.html#a8">Y</a>(), 0);
00143
00144 <span class="keywordflow">if</span>( glList)
00145 {
00146 glCallList( glList);
00147 }
00148
00149 <span class="keywordflow">return</span> advance;
00150 }
00151
00152
00153 <a class="code" href="classFTPoint.html">FTPoint</a> FTExtrdGlyph::GetNormal( <span class="keyword">const</span> <a class="code" href="classFTPoint.html">FTPoint</a> &amp;a, <span class="keyword">const</span> <a class="code" href="classFTPoint.html">FTPoint</a> &amp;b)
00154 {
00155 <span class="keywordtype">float</span> vectorX = a.<a class="code" href="classFTPoint.html#a7">X</a>() - b.<a class="code" href="classFTPoint.html#a7">X</a>();
00156 <span class="keywordtype">float</span> vectorY = a.<a class="code" href="classFTPoint.html#a8">Y</a>() - b.<a class="code" href="classFTPoint.html#a8">Y</a>();
00157
00158 <span class="keywordtype">float</span> length = sqrt( vectorX * vectorX + vectorY * vectorY );
00159
00160 <span class="keywordflow">if</span>( length &gt; 0.01f)
00161 {
00162 length = 1 / length;
00163 }
00164 <span class="keywordflow">else</span>
00165 {
00166 length = 0.0f;
00167 }
00168
00169 <span class="keywordflow">return</span> <a class="code" href="classFTPoint.html">FTPoint</a>( -vectorY * length,
00170 vectorX * length,
00171 0.0f);
00172 }
00173
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Dec 5 22:24:05 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>