Commit b6f636a5f28931b4a9686b87b2a0b0f5ee18fa4c

henry 2001-08-02T22:59:13

Polygon fonts now work.

diff --git a/include/FTGLPolygonFont.h b/include/FTGLPolygonFont.h
index 4b7407a..fc12078 100755
--- a/include/FTGLPolygonFont.h
+++ b/include/FTGLPolygonFont.h
@@ -1,9 +1,13 @@
-#ifndef		__FTGLPolygonFont
-#define		__FTGLPolygonFont
+#ifndef		__FTGLPolygonFont__
+#define		__FTGLPolygonFont__
+
 #include	"FTFont.h"
 
 #include "FTGL.h"
 
+
+class FTPolyGlyph;
+
 class	FTGLPolygonFont : public FTFont
 {
 	public:
@@ -17,5 +21,9 @@ class	FTGLPolygonFont : public FTFont
 		// methods
 		bool MakeGlyphList();
 		
+		// attributes
+		FTPolyGlyph* tempGlyph;
+
+		
 };
-#endif
+#endif	//	__FTGLPolygonFont__
diff --git a/include/FTPolyGlyph.h b/include/FTPolyGlyph.h
new file mode 100644
index 0000000..b254ce2
--- /dev/null
+++ b/include/FTPolyGlyph.h
@@ -0,0 +1,37 @@
+#ifndef		__FTPolyGlyph__
+#define		__FTPolyGlyph__
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
+
+#include "FTGlyph.h"
+
+class FTVectoriser;
+
+class	FTPolyGlyph : public FTGlyph
+{
+	public:
+		// methods
+		FTPolyGlyph( FT_Glyph glyph, int glyphIndex);
+		virtual ~FTPolyGlyph();
+		virtual float Render( FT_Vector& pen);
+		
+		// attributes
+	
+	private:
+		// methods
+		void Tesselate();
+		
+		// attributes
+		FTVectoriser* vectoriser;
+		int numPoints;
+		int numContours;
+		int * contourLength;
+		float* data;
+		int glList;
+	
+};
+
+
+#endif	//	__FTPolyGlyph__
diff --git a/src/FTGLPolygonFont.cpp b/src/FTGLPolygonFont.cpp
index c3a0dbd..8b1615b 100755
--- a/src/FTGLPolygonFont.cpp
+++ b/src/FTGLPolygonFont.cpp
@@ -1,9 +1,16 @@
+#include	"gl.h"
+
 #include	"FTGLPolygonFont.h"
 #include	"FTGlyphContainer.h"
 #include	"FTGL.h"
+#include	"FTPolyGlyph.h"
+
 
 
-	FTGLPolygonFont::FTGLPolygonFont()
+FTGLPolygonFont::FTGLPolygonFont()
+//Insert your own initialization here.
+
+//End of user initialization.         
 {
 //Insert your own code here.
 
@@ -18,3 +25,30 @@ FTGLPolygonFont::~FTGLPolygonFont()
 //End of user code.         
 }
 
+
+bool FTGLPolygonFont::MakeGlyphList()
+{
+	int glyphIndex;
+	
+	numGlyphs = 127;
+	
+	for( int n = 0; n < numGlyphs; ++n)
+	{
+		FT_Face* ftFace = face.Face();
+
+		glyphIndex = FT_Get_Char_Index( *ftFace, n);
+		
+		err = FT_Load_Glyph( *ftFace, glyphIndex, FT_LOAD_DEFAULT);
+		if( err)
+		{ }
+
+		FT_Glyph ftGlyph;
+		
+		err = FT_Get_Glyph( (*ftFace)->glyph, &ftGlyph);
+		if( err)
+		{}
+		
+		tempGlyph = new FTPolyGlyph( ftGlyph, glyphIndex);
+		glyphList->Add( tempGlyph);
+	}
+}
diff --git a/src/FTPolyGlyph.cpp b/src/FTPolyGlyph.cpp
new file mode 100644
index 0000000..2290a00
--- /dev/null
+++ b/src/FTPolyGlyph.cpp
@@ -0,0 +1,155 @@
+#include <stdio.h>
+
+
+#include	"gl.h"
+#include	"glu.h"
+
+#include	"FTPolyGlyph.h"
+#include	"FTVectoriser.h"
+#include	"FTGL.h"
+
+
+#ifndef CALLBACK
+#define CALLBACK
+#endif
+
+
+void ftglError( GLenum errCode)
+{
+//	const GLubyte* estring;
+//	estring = gluErrorString( errCode);
+//	fprintf( stderr, "ERROR : %s\n", estring);
+//	exit(1);
+}
+
+void ftglVertex( void* data)
+{
+	glVertex3dv( (double*)data);
+}
+
+
+void ftglBegin( GLenum type)
+{
+	glBegin( type);
+}
+
+
+void ftglEnd()
+{
+	glEnd();
+}
+
+
+void ftglCombine( GLdouble coords[3], void* vertex_data[4], GLfloat weight[4], void** outData)
+{
+	double* vertex = new double[3];
+	
+	vertex[0] = coords[0];
+	vertex[1] = coords[1];
+	vertex[2] = coords[2];
+
+	*outData = vertex;
+}
+
+
+FTPolyGlyph::FTPolyGlyph( FT_Glyph glyph, int gi)
+:	FTGlyph(gi),
+	vectoriser(0),
+	numPoints(0),
+	numContours(0),
+	contourLength(0),
+	data(0)
+{
+	if( glyph->format == ft_glyph_format_outline)
+	{
+		vectoriser = new FTVectoriser( glyph);
+		
+		if( vectoriser->Ingest())
+		{
+			numContours = vectoriser->contours();
+			
+			contourLength = new int[ numContours];
+			
+			for( int c = 0; c < numContours; ++c)
+			{
+				contourLength[c] = vectoriser->contourSize( c);
+			}
+			
+
+			numPoints = vectoriser->points();
+			data = new double[ numPoints * 3];
+			vectoriser->Output( data);
+			
+			contourFlag = vectoriser->contourFlag;
+			advance = glyph->advance.x >> 16; // this is 6 in the freetype docs!!!!!!
+		}
+	
+		delete vectoriser;
+
+	    if ( ( numContours < 1) || ( numPoints < 3))
+			return;
+
+		Tesselate();
+	}
+}
+
+
+void FTPolyGlyph::Tesselate()
+{
+	glList = glGenLists(1);
+	GLUtesselator* tobj = gluNewTess();
+	int d = 0;
+	
+	gluTessCallback( tobj, GLU_TESS_BEGIN, (void (CALLBACK*)())ftglBegin);
+	gluTessCallback( tobj, GLU_TESS_VERTEX, (void (CALLBACK*)())ftglVertex);
+	gluTessCallback( tobj, GLU_TESS_COMBINE, (void (CALLBACK*)())ftglCombine);
+	gluTessCallback( tobj, GLU_TESS_END, ftglEnd);
+	gluTessCallback( tobj, GLU_TESS_ERROR, (void (CALLBACK*)())ftglError);
+	
+	glNewList( glList, GL_COMPILE);
+	
+//		if( contourFlag & ft_outline_even_odd_fill)
+//		{
+//			gluTessProperty( tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD);
+//		}
+//		else
+//		{
+//			gluTessProperty( tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO);
+//		}
+//		
+		gluTessProperty( tobj, GLU_TESS_TOLERANCE, 0);
+		gluTessBeginPolygon( tobj, NULL);
+		
+			for( int c = 0; c < numContours; ++c)
+			{
+				gluTessBeginContour( tobj);
+					for( int p = 0; p < ( contourLength[c]); ++p)
+					{
+						gluTessVertex( tobj, data + d, data + d);
+						d += 3;
+					}
+				gluTessEndContour( tobj);
+			}
+			
+		gluTessEndPolygon( tobj);
+		
+	glEndList();
+
+	gluDeleteTess( tobj);
+}
+
+
+FTPolyGlyph::~FTPolyGlyph()
+{
+	delete [] data;
+}
+
+
+float FTPolyGlyph::Render( FT_Vector& pen)
+{
+	glTranslatef( pen.x, pen.y, 0);
+		glCallList( glList);	
+	glTranslatef( -pen.x, -pen.y, 0);
+	
+	return advance;
+}