From 5853215f1c1b239731f3349a8b4e97eb969ae134 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 24 Oct 2001 09:41:42 +0000 Subject: [PATCH] Updated FTGL version to 1.0 and removed a couple of warnings in the osgText demo. --- src/Demos/osgtext/main.cpp | 2 - src/osgText/FTBitmapGlyph.cpp | 3 - src/osgText/FTBitmapGlyph.h | 40 +++++-- src/osgText/FTCharmap.h | 21 +++- src/osgText/FTFace.h | 7 +- src/osgText/FTFont.h | 9 +- src/osgText/FTGL.h | 79 ++++++++++++- src/osgText/FTGLBitmapFont.cpp | 2 - src/osgText/FTGLBitmapFont.h | 8 +- src/osgText/FTGLOutlineFont.cpp | 2 - src/osgText/FTGLOutlineFont.h | 42 +++++-- src/osgText/FTGLPixmapFont.cpp | 3 +- src/osgText/FTGLPixmapFont.h | 37 +++++- src/osgText/FTGLPolygonFont.h | 30 +++-- src/osgText/FTGLTextureFont.cpp | 10 +- src/osgText/FTGLTextureFont.h | 136 +++++++++++++++++++--- src/osgText/FTGlyph.h | 7 +- src/osgText/FTGlyphContainer.h | 46 +++++--- src/osgText/FTLibrary.cpp | 1 - src/osgText/FTLibrary.h | 13 +-- src/osgText/FTOutlineGlyph.cpp | 3 +- src/osgText/FTOutlineGlyph.h | 59 ++++++++-- src/osgText/FTPixmapGlyph.cpp | 2 - src/osgText/FTPixmapGlyph.h | 43 ++++++- src/osgText/FTPolyGlyph.cpp | 4 +- src/osgText/FTPolyGlyph.h | 67 ++++++++++- src/osgText/FTSize.h | 6 +- src/osgText/FTTextureGlyph.cpp | 3 +- src/osgText/FTTextureGlyph.h | 74 ++++++++++-- src/osgText/FTVectorGlyph.cpp | 87 ++++++++++++++ src/osgText/FTVectorGlyph.h | 36 ++++++ src/osgText/FTVectoriser.h | 194 +++++++++++++++++++++++++++++--- src/osgText/Makefile | 3 +- 33 files changed, 921 insertions(+), 158 deletions(-) create mode 100644 src/osgText/FTVectorGlyph.cpp create mode 100644 src/osgText/FTVectorGlyph.h diff --git a/src/Demos/osgtext/main.cpp b/src/Demos/osgtext/main.cpp index e84bb4537..f23027449 100644 --- a/src/Demos/osgtext/main.cpp +++ b/src/Demos/osgtext/main.cpp @@ -65,7 +65,6 @@ void set2dScene(osg::Group* rootNode) osgText::Text* text; osg::Geode* geode; osg::Material* textMaterial; - osg::Vec4 textColor; osg::StateSet* textState; double xOffset=250; double yOffset=gFontSize+10; @@ -250,7 +249,6 @@ void setScene(osg::Group* rootNode) osgText::Text* text; osg::Geode* geode; osg::Material* textMaterial; - osg::Vec4 textColor; osg::StateSet* textState; double xOffset=0; double yOffset=0; diff --git a/src/osgText/FTBitmapGlyph.cpp b/src/osgText/FTBitmapGlyph.cpp index 07af04acd..d7af2c805 100644 --- a/src/osgText/FTBitmapGlyph.cpp +++ b/src/osgText/FTBitmapGlyph.cpp @@ -1,7 +1,4 @@ -#include "GL/gl.h" - #include "FTBitmapGlyph.h" -#include "FTGL.h" FTBitmapGlyph::FTBitmapGlyph( FT_Glyph glyph) diff --git a/src/osgText/FTBitmapGlyph.h b/src/osgText/FTBitmapGlyph.h index d650ba576..2e4419805 100644 --- a/src/osgText/FTBitmapGlyph.h +++ b/src/osgText/FTBitmapGlyph.h @@ -1,6 +1,8 @@ #ifndef __FTBitmapGlyph__ #define __FTBitmapGlyph__ +#include "FTGL.h" + #include #include FT_FREETYPE_H #include FT_GLYPH_H @@ -8,41 +10,57 @@ #include "FTGlyph.h" -class FTBitmapGlyph : public FTGlyph +/** + * FTBitmapGlyph is a specialisation of FTGlyph for creating bitmaps. + * + * It provides the interface between Freetype glyphs and their openGL + * renderable counterparts. This is an abstract class and derived classes + * must implement the render function. + * + * @see FTGlyphContainer + * + */ +class FTGL_EXPORT FTBitmapGlyph : public FTGlyph { public: /** * Constructor * - * @param + * @param glyph The Freetype glyph to be processed */ FTBitmapGlyph( FT_Glyph glyph); /** - * + * Destructor */ virtual ~FTBitmapGlyph(); /** + * Renders this glyph at the current pen position. * - * @param pen - * - * @return + * @param pen The current pen position. + * @return The advance distance for this glyph. */ virtual float Render( const FT_Vector& pen); - // attributes - private: - // methods - - // attributes + /** + * The width of the glyph 'image' + */ int destWidth; + + /** + * The height of the glyph 'image' + */ int destHeight; + /** + * Pointer to the 'image' data + */ unsigned char* data; }; #endif // __FTBitmapGlyph__ + diff --git a/src/osgText/FTCharmap.h b/src/osgText/FTCharmap.h index db0edd8de..816704bdb 100644 --- a/src/osgText/FTCharmap.h +++ b/src/osgText/FTCharmap.h @@ -1,6 +1,8 @@ #ifndef __FTCharmap__ #define __FTCharmap__ +#include "FTGL.h" + #include #include @@ -13,11 +15,16 @@ using namespace std; /** - * FTCharmap + * FTCharmap takes care of specifying the encodeing for a font and mapping + * character codes to glyph indices. + * + * It doesn't preprocess all indices, only on as needed basis. This may seem + * like a performance penalty but it is quicker than using the 'raw' + * freetype calls and will save significant amounts of memory when dealing + * with uncode encoding * - * */ -class FTCharmap +class FTGL_EXPORT FTCharmap { public: /** @@ -91,8 +98,16 @@ class FTCharmap */ FT_Encoding ftEncoding; + /** + * The current Freetype face. + */ FT_Face ftFace; + /** + * A structure that maps glyph indices to character codes + * + * < character code, face glyph index> + */ typedef map< unsigned long, unsigned long> CharacterMap; CharacterMap charMap; diff --git a/src/osgText/FTFace.h b/src/osgText/FTFace.h index 9ba7514cc..86924ca8c 100644 --- a/src/osgText/FTFace.h +++ b/src/osgText/FTFace.h @@ -1,7 +1,7 @@ #ifndef __FTFace__ #define __FTFace__ -//#include "FTGL.h" +#include "FTGL.h" #include #include FT_FREETYPE_H @@ -17,7 +17,7 @@ class FTCharmap; * @see "Freetype 2 Documentation - 2.0.4" * */ -class FTFace +class FTGL_EXPORT FTFace { public: /** @@ -61,6 +61,9 @@ class FTFace /** * Sets the character map for the face. * + * This doesn't guarantee that the size was set correctly. Clients + * should check errors. + * * @param encoding the Freetype encoding symbol. See above. * @return true if charmap was valid * and set correctly diff --git a/src/osgText/FTFont.h b/src/osgText/FTFont.h index 70650c236..6b6c2d934 100644 --- a/src/osgText/FTFont.h +++ b/src/osgText/FTFont.h @@ -3,6 +3,8 @@ #include +#include "FTGL.h" + #include #include FT_FREETYPE_H @@ -30,7 +32,7 @@ using namespace std; * @see FTGlyphContainer * @see FTGlyph */ -class FTFont +class FTGL_EXPORT FTFont { public: /** @@ -118,8 +120,7 @@ class FTFont * @param string wchar_t string to be output. */ virtual void render( const wchar_t* string ); - - + /** * Queries the Font for errors. * @@ -141,6 +142,7 @@ class FTFont * Current face object */ FTFace face; + /** * Number of faces in this font */ @@ -177,3 +179,4 @@ class FTFont #endif // __FTFont__ + diff --git a/src/osgText/FTGL.h b/src/osgText/FTGL.h index 789d33d6f..5d554d8de 100644 --- a/src/osgText/FTGL.h +++ b/src/osgText/FTGL.h @@ -1,7 +1,84 @@ #ifndef __FTGL__ #define __FTGL__ -// For Future? + +#ifdef WIN32 + // stl stuff + #pragma warning( disable : 4251 ) + #pragma warning( disable : 4275 ) + #pragma warning( disable : 4786 ) + +#endif + +#ifndef WIN32 + + // non windows, doesn't require nonesense as seen below :-) + #ifndef __gl_h_ + #include + #endif + + // required for compatibility with glext.h style function definitions of + // OpenGL extensions, such as in src/osg/Point.cpp. + #ifndef APIENTRY + #define APIENTRY + #endif + +#else + + // Under windows avoid including + // to avoid name space pollution, but Win32's + // needs APIENTRY and WINGDIAPI defined properly. + // F + # if 0 + # define WIN32_LEAN_AND_MEAN + # include + # else + // XXX This is from Win32's + # ifndef APIENTRY + # define GLUT_APIENTRY_DEFINED + # if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) + # define APIENTRY __stdcall + # else + # define APIENTRY + # endif + # endif + // XXX This is from Win32's + # ifndef CALLBACK + # if (defined(_M_MRX000) || defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_PPC)) && !defined(MIDL_PASS) + # define CALLBACK __stdcall + # else + # define CALLBACK + # endif + # endif + // XXX This is from Win32's and + # ifndef WINGDIAPI + # define GLUT_WINGDIAPI_DEFINED + # define WINGDIAPI __declspec(dllimport) + # endif + // XXX This is from Win32's + # ifndef _WCHAR_T_DEFINED + typedef unsigned short wchar_t; + # define _WCHAR_T_DEFINED + # endif + # endif + + #ifndef __gl_h_ + #include + #endif + +#endif + +#if defined(_MSC_VER) + # ifdef FTGL_LIBRARY_STATIC // staticLib + # define FTGL_EXPORT + # elif FTGL_LIBRARY // dynamicLib + # define FTGL_EXPORT __declspec(dllexport) + # else + # define FTGL_EXPORT __declspec(dllimport) + # endif /* FTGL_LIBRARY */ +#else + # define FTGL_EXPORT +#endif #endif // __FTGL__ diff --git a/src/osgText/FTGLBitmapFont.cpp b/src/osgText/FTGLBitmapFont.cpp index c85e18c46..9e1c56d2b 100644 --- a/src/osgText/FTGLBitmapFont.cpp +++ b/src/osgText/FTGLBitmapFont.cpp @@ -1,5 +1,3 @@ -#include "GL/gl.h" - #include "FTGLBitmapFont.h" #include "FTGlyphContainer.h" #include "FTBitmapGlyph.h" diff --git a/src/osgText/FTGLBitmapFont.h b/src/osgText/FTGLBitmapFont.h index cf827af8e..43e4e2061 100644 --- a/src/osgText/FTGLBitmapFont.h +++ b/src/osgText/FTGLBitmapFont.h @@ -2,7 +2,9 @@ #define __FTGLBitmapFont__ -#include "FTFont.h" +#include "FTGL.h" + +#include "FTFont.h" class FTBitmapGlyph; @@ -12,7 +14,7 @@ class FTBitmapGlyph; * * @see FTFont */ -class FTGLBitmapFont : public FTFont +class FTGL_EXPORT FTGLBitmapFont : public FTFont { public: /** @@ -35,7 +37,7 @@ class FTGLBitmapFont : public FTFont /** * Renders a string of characters * - * @param string 'C' style string to be output. + * @param string 'C' style wide string to be output. */ void render( const wchar_t* string); diff --git a/src/osgText/FTGLOutlineFont.cpp b/src/osgText/FTGLOutlineFont.cpp index 9a06af92b..25a4ed3cc 100644 --- a/src/osgText/FTGLOutlineFont.cpp +++ b/src/osgText/FTGLOutlineFont.cpp @@ -1,5 +1,3 @@ -#include "GL/gl.h" - #include "FTGLOutlineFont.h" #include "FTGlyphContainer.h" #include "FTGL.h" diff --git a/src/osgText/FTGLOutlineFont.h b/src/osgText/FTGLOutlineFont.h index 172100aba..fee7499ff 100644 --- a/src/osgText/FTGLOutlineFont.h +++ b/src/osgText/FTGLOutlineFont.h @@ -1,10 +1,10 @@ -#ifndef __FTGLOutlineFont -#define __FTGLOutlineFont +#ifndef __FTGLOutlineFont__ +#define __FTGLOutlineFont__ - -#include "FTFont.h" #include "FTGL.h" +#include "FTFont.h" + class FTOutlineGlyph; @@ -14,24 +14,48 @@ class FTOutlineGlyph; * * @see FTFont */ -class FTGLOutlineFont : public FTFont +class FTGL_EXPORT FTGLOutlineFont : public FTFont { public: - // methods + /** + * Default Constructor + */ FTGLOutlineFont(); + + /** + * Destructor + */ ~FTGLOutlineFont(); + /** + * Renders a string of characters + * + * @param string 'C' style string to be output. + */ void render( const char* string); + + /** + * Renders a string of characters + * + * @param string wchar_t string to be output. + */ void render( const wchar_t* string); // attributes private: - // methods + /** + * Constructs the internal glyph cache. + * + * This a list of glyphs processed for openGL rendering NOT + * freetype glyphs + */ bool MakeGlyphList(); - // attributes + /** + * A temporary FTOutlineGlyph used for building the glyphList + */ FTOutlineGlyph* tempGlyph; }; -#endif +#endif // __FTGLOutlineFont__ diff --git a/src/osgText/FTGLPixmapFont.cpp b/src/osgText/FTGLPixmapFont.cpp index e00d1f9ad..0fe7caa11 100644 --- a/src/osgText/FTGLPixmapFont.cpp +++ b/src/osgText/FTGLPixmapFont.cpp @@ -1,5 +1,3 @@ -#include "GL/gl.h" - #include "FTGLPixmapFont.h" #include "FTGlyphContainer.h" #include "FTPixmapGlyph.h" @@ -64,3 +62,4 @@ void FTGLPixmapFont::render( const wchar_t* string) glPopAttrib(); } + diff --git a/src/osgText/FTGLPixmapFont.h b/src/osgText/FTGLPixmapFont.h index d0422bdd9..05cf17165 100644 --- a/src/osgText/FTGLPixmapFont.h +++ b/src/osgText/FTGLPixmapFont.h @@ -2,7 +2,9 @@ #define __FTGLPixmapFont__ -#include "FTFont.h" +#include "FTGL.h" + +#include "FTFont.h" class FTPixmapGlyph; @@ -12,25 +14,50 @@ class FTPixmapGlyph; * * @see FTFont */ -class FTGLPixmapFont : public FTFont +class FTGL_EXPORT FTGLPixmapFont : public FTFont { public: - // methods + /** + * Default Constructor + */ FTGLPixmapFont(); + + /** + * Destructor + */ ~FTGLPixmapFont(); + /** + * Renders a string of characters + * + * @param string 'C' style string to be output. + */ void render( const char* string); + + /** + * Renders a string of characters + * + * @param string wchar_t string to be output. + */ void render( const wchar_t* string); private: - // methods + /** + * Constructs the internal glyph cache. + * + * This a list of glyphs processed for openGL rendering NOT + * freetype glyphs + */ bool MakeGlyphList(); - // attributes + /** + * A temporary FTPixmapGlyph used for building the glyphList + */ FTPixmapGlyph* tempGlyph; }; #endif // __FTGLPixmapFont__ + diff --git a/src/osgText/FTGLPolygonFont.h b/src/osgText/FTGLPolygonFont.h index 27c41ce60..92c3b9aa9 100644 --- a/src/osgText/FTGLPolygonFont.h +++ b/src/osgText/FTGLPolygonFont.h @@ -1,10 +1,10 @@ #ifndef __FTGLPolygonFont__ #define __FTGLPolygonFont__ -#include "FTFont.h" - #include "FTGL.h" +#include "FTFont.h" + class FTPolyGlyph; @@ -14,22 +14,36 @@ class FTPolyGlyph; * * @see FTFont */ -class FTGLPolygonFont : public FTFont +class FTGL_EXPORT FTGLPolygonFont : public FTFont { public: - // methods + /** + * Default Constructor + */ FTGLPolygonFont(); + + /** + * Destructor + */ ~FTGLPolygonFont(); - // attributes - private: - // methods + /** + * Constructs the internal glyph cache. + * + * This a list of glyphs processed for openGL rendering NOT + * freetype glyphs + */ bool MakeGlyphList(); - // attributes + /** + * A temporary FTPolyGlyph used for building the glyphList + */ FTPolyGlyph* tempGlyph; }; + + #endif // __FTGLPolygonFont__ + diff --git a/src/osgText/FTGLTextureFont.cpp b/src/osgText/FTGLTextureFont.cpp index 8a3e21d5a..74c9b42fc 100644 --- a/src/osgText/FTGLTextureFont.cpp +++ b/src/osgText/FTGLTextureFont.cpp @@ -1,8 +1,5 @@ -#include "GL/gl.h" - #include "FTGLTextureFont.h" #include "FTGlyphContainer.h" -#include "FTGL.h" #include "FTTextureGlyph.h" using namespace std; @@ -44,9 +41,11 @@ FTGLTextureFont::~FTGLTextureFont() bool FTGLTextureFont::MakeGlyphList() { + glEnable( GL_TEXTURE_2D); + if( !maxTextSize) glGetIntegerv( GL_MAX_TEXTURE_SIZE, (GLint*)&maxTextSize); - + glyphHeight = ( charSize.Height()) + padding; glyphWidth = ( charSize.Width()) + padding; @@ -91,7 +90,7 @@ bool FTGLTextureFont::MakeGlyphList() glGenTextures( numTextures, (GLuint*)&glTextureID[0]); textMem = new unsigned char[totalMem]; // GL_ALPHA texture; - std::memset( textMem, 0, totalMem); + memset( textMem, 0, totalMem); FillGlyphs( 0, glTextureID[0], textureWidth, textureHeight, textMem); CreateTexture( 0, textureWidth, textureHeight, textMem); @@ -208,3 +207,4 @@ void FTGLTextureFont::render( const wchar_t* string) glPopAttrib(); } + diff --git a/src/osgText/FTGLTextureFont.h b/src/osgText/FTGLTextureFont.h index 81e296bff..0f5ec016d 100644 --- a/src/osgText/FTGLTextureFont.h +++ b/src/osgText/FTGLTextureFont.h @@ -1,8 +1,8 @@ -#ifndef __FTGLTextureFont -#define __FTGLTextureFont -#include "FTFont.h" +#ifndef __FTGLTextureFont__ +#define __FTGLTextureFont__ #include "FTGL.h" +#include "FTFont.h" class FTTextureGlyph; @@ -12,43 +12,149 @@ class FTTextureGlyph; * * @see FTFont */ -class FTGLTextureFont : public FTFont +class FTGL_EXPORT FTGLTextureFont : public FTFont { public: - // methods + /** + * Default Constructor + */ FTGLTextureFont(); + + /** + * Destructor + */ virtual ~FTGLTextureFont(); + /** + * Get the total width of the texture that holds this font + */ virtual int TextureWidth() const { return textureWidth;} + + /** + * Get the total height of the texture that holds this font + */ virtual int TextureHeight() const { return textureHeight;} + /** + * Renders a string of characters + * + * @param string 'C' style string to be output. + */ virtual void render( const char* string); + + /** + * Renders a string of characters + * + * @param string wchar_t string to be output. + */ virtual void render( const wchar_t* string); private: - // attributes + /** + * Constructs the internal glyph cache. + * + * This a list of glyphs processed for openGL rendering NOT + * freetype glyphs + */ + bool MakeGlyphList(); + + /** + * Draw a series of glyphs into texture memory + * + * This function will start with glyph index glyphStart and draw each + * glyph into the texture until it runs out of space in the current + * texture. It will return the index of the last glyph it drew so + * that if more textures are required, we know where to start from. + * + * @param glyphStart The index of the first glyph to be drawn + * @param textID The index of the openGLtexture to draw glyphs into + * @param textureWidth The texture width + * @param textureHeight The texture height + * @param textMem A pointer to the texture memory. + */ + unsigned int FillGlyphs( unsigned int glyphStart, int textID, int textureWidth, int textureHeight, unsigned char* textMem); + + /** + * Get the size of a block of memory required to layout the glyphs + * + * Calculates a width and height based on the glyph sizes and the + * number of glyphs. + */ + void GetSize(); + + /** + * Creates an OpenGL texture object. + * + * The format is GL_ALPHA and the params are + * GL_TEXTURE_WRAP_S = GL_CLAMP + * GL_TEXTURE_WRAP_T = GL_CLAMP + * GL_TEXTURE_MAG_FILTER = GL_LINEAR + * GL_TEXTURE_MIN_FILTER = GL_LINEAR + * Note that mipmapping is NOT used + * @param id The index into an array of glTextureIDs. + * @param width The width of the texture in bytes + * @param height The number of rows of bytes. + * @param data A pointer to the texture data + */ + void CreateTexture( int id, int width, int height, unsigned char* data); + + /** + * A temporary FTTextureGlyph used for building the glyphList + */ FTTextureGlyph* tempGlyph; + + /** + * The maximum texture dimension on this OpenGL implemetation + */ long maxTextSize; + + /** + * The minimum texture width required to hold the glyphs + */ int textureWidth; + + /** + * The minimum texture height required to hold the glyphs + */ int textureHeight; + /** + * An array of texture ids + */ unsigned long glTextureID[16]; + + /** + * The number of textures required to hold the glyphs + */ int numTextures; + + /** + * The memeory where the textures are built before beiing transferred + * to OpenGL + */ unsigned char* textMem; + /** + * The max height for glyphs in the current font + */ int glyphHeight; + + /** + * The max width for glyphs in the current font + */ int glyphWidth; + /** + * A value to be added to the height and width to ensure that + * glyphs don't overlap in the texture + */ int padding; - - // methods - bool MakeGlyphList(); - void CreateTexture( int id, int width, int height, unsigned char* data); - void GetSize(); - unsigned int FillGlyphs( unsigned int glyphStart, int textID, int textureWidth, int textureHeight, unsigned char* textMem); - - + }; -#endif + + +#endif // __FTGLTextureFont__ + + diff --git a/src/osgText/FTGlyph.h b/src/osgText/FTGlyph.h index 5002d06df..0f4000f6f 100644 --- a/src/osgText/FTGlyph.h +++ b/src/osgText/FTGlyph.h @@ -1,6 +1,8 @@ #ifndef __FTGlyph__ #define __FTGlyph__ +#include "FTGL.h" + #include #include FT_FREETYPE_H #include FT_GLYPH_H @@ -8,7 +10,7 @@ //#include "FTGL.h" /** - * FTGlyph is the base clas for FTGL glyphs. + * FTGlyph is the base class for FTGL glyphs. * * It provides the interface between Freetype glyphs and their openGL * renderable counterparts. This is an abstract class and derived classes @@ -17,7 +19,7 @@ * @see FTGlyphContainer * */ -class FTGlyph +class FTGL_EXPORT FTGlyph { public: /** @@ -74,3 +76,4 @@ class FTGlyph #endif // __FTGlyph__ + diff --git a/src/osgText/FTGlyphContainer.h b/src/osgText/FTGlyphContainer.h index c2d3a930c..b5e8a5548 100644 --- a/src/osgText/FTGlyphContainer.h +++ b/src/osgText/FTGlyphContainer.h @@ -1,6 +1,8 @@ #ifndef __FTGlyphContainer__ #define __FTGlyphContainer__ +#include "FTGL.h" + #include #include @@ -14,15 +16,20 @@ class FTGlyph; using namespace std; /** - * FTGlyphContainer + * FTGlyphContainer holds the post processed FTGlyph objects. * * @see FTGlyph */ -class FTGlyphContainer +class FTGL_EXPORT FTGlyphContainer { public: /** * Constructor + * + * @param face The Freetype face + * @param numGlyphs the number of glyphs in this face + * @param p A flag to indicate preprocessing of glyphs. + * Not used. */ FTGlyphContainer( FTFace* face, int numGlyphs, bool p = false); @@ -45,54 +52,63 @@ class FTGlyphContainer * param index glyph index of the character * param next the next glyph in a string * return advance width - * */ float Advance( unsigned int index, unsigned int next); /** * renders a character + * @param index the glyph to be rendered + * @param next the next glyph in the string. Used for kerning. + * @param pen the position to render the glyph + * return The distance to advance the pen position after rendering */ FT_Vector& render( unsigned int index, unsigned int next, FT_Vector pen); + /** + * Queries the Font for errors. + * + * @return The current error code. + */ + virtual FT_Error Error() const { return err;} + private: /** - * - */ - FT_Error err; - - /** - * + * A flag to indicate preprocessing of glyphs. Not used. */ bool preCache; /** - * + * How meny glyphs are stored in this container */ int numGlyphs; /** - * + * The current Freetype face */ FTFace* face; - /** - * + * The kerning vector for the current pair of glyphs */ FT_Vector kernAdvance; /** - * + * The advance for the glyph being rendered */ float advance; /** - * + * A structure to hold the glyphs */ vector glyphs; // typedef pair CHARREF; // glyphIndex, glyph // vector glyphs; // map< int, FTGlyph*> CHARREF; // charCode, glyph + + /** + * Current error code. Zero means no error. + */ + FT_Error err; }; diff --git a/src/osgText/FTLibrary.cpp b/src/osgText/FTLibrary.cpp index 5a6369c1f..72788c023 100644 --- a/src/osgText/FTLibrary.cpp +++ b/src/osgText/FTLibrary.cpp @@ -1,5 +1,4 @@ #include "FTLibrary.h" -#include "FTGL.h" FTLibrary& FTLibrary::Instance() diff --git a/src/osgText/FTLibrary.h b/src/osgText/FTLibrary.h index ce922b9c2..2074850de 100644 --- a/src/osgText/FTLibrary.h +++ b/src/osgText/FTLibrary.h @@ -1,13 +1,12 @@ #ifndef __FTLibrary__ #define __FTLibrary__ +#include "FTGL.h" #include #include FT_FREETYPE_H //#include FT_CACHE_H -#include "FTGL.h" - /** * FTLibrary class is the global accessor for the Freetype library. @@ -27,10 +26,9 @@ * @see "Freetype 2 Documentation - 2.0.4" * */ -class FTLibrary +class FTGL_EXPORT FTLibrary { public: - // methods /** * Global acces point to the single FTLibrary object. * @@ -59,10 +57,7 @@ class FTLibrary */ virtual ~FTLibrary(); - // attributes - private: - // methods /** * Default constructors. * @@ -71,7 +66,7 @@ class FTLibrary */ FTLibrary(); FTLibrary( const FT_Library&){} - FTLibrary& operator=( const FT_Library&){} + FTLibrary& operator=( const FT_Library&) { return *this; } /** * Initialises the Freetype library @@ -84,8 +79,6 @@ class FTLibrary * otherwise. */ bool Init(); - - // attributes /** * Freetype library handle. */ diff --git a/src/osgText/FTOutlineGlyph.cpp b/src/osgText/FTOutlineGlyph.cpp index 8e5387112..67d0919da 100644 --- a/src/osgText/FTOutlineGlyph.cpp +++ b/src/osgText/FTOutlineGlyph.cpp @@ -1,5 +1,3 @@ -#include "GL/gl.h" - #include "FTOutlineGlyph.h" #include "FTVectoriser.h" #include "FTGL.h" @@ -81,3 +79,4 @@ float FTOutlineGlyph::Render( const FT_Vector& pen) return advance; } + diff --git a/src/osgText/FTOutlineGlyph.h b/src/osgText/FTOutlineGlyph.h index eb2dd37e2..9e1e0f003 100644 --- a/src/osgText/FTOutlineGlyph.h +++ b/src/osgText/FTOutlineGlyph.h @@ -1,6 +1,8 @@ #ifndef __FTOutlineGlyph__ #define __FTOutlineGlyph__ +#include "FTGL.h" + #include #include FT_FREETYPE_H #include FT_GLYPH_H @@ -9,28 +11,71 @@ class FTVectoriser; -class FTOutlineGlyph : public FTGlyph + +/** + * FTOutlineGlyph is a specialisation of FTGlyph for creating outlines. + * + * @see FTGlyphContainer + * @see FTVectoriser + * + */ +class FTGL_EXPORT FTOutlineGlyph : public FTGlyph { public: - // methods + /** + * Constructor + * + * @param glyph The Freetype glyph to be processed + */ FTOutlineGlyph( FT_Glyph glyph); + + /** + * Destructor + */ virtual ~FTOutlineGlyph(); + + /** + * Renders this glyph at the current pen position. + * + * @param pen The current pen position. + * @return The advance distance for this glyph. + */ virtual float Render( const FT_Vector& pen); - // attributes - private: - // methods - - // attributes + /** + * An object that helps convert freetype outlines into point + * data + */ FTVectoriser* vectoriser; + + /** + * The total number of points in the Freetype outline + */ int numPoints; + + /** + * The totals number of contours in the Freetype outline + */ int numContours; + + /** + * An array containing the number of points in each outline + */ int* contourLength; + + /** + * Pointer to the point data + */ double* data; + + /** + * OpenGL display list + */ int glList; }; #endif // __FTOutlineGlyph__ + diff --git a/src/osgText/FTPixmapGlyph.cpp b/src/osgText/FTPixmapGlyph.cpp index 1970be9ff..8dd587358 100644 --- a/src/osgText/FTPixmapGlyph.cpp +++ b/src/osgText/FTPixmapGlyph.cpp @@ -1,5 +1,3 @@ -#include "GL/gl.h" - #include "FTPixmapGlyph.h" #include "FTGL.h" diff --git a/src/osgText/FTPixmapGlyph.h b/src/osgText/FTPixmapGlyph.h index 3485e8d87..7b3e31538 100644 --- a/src/osgText/FTPixmapGlyph.h +++ b/src/osgText/FTPixmapGlyph.h @@ -1,6 +1,8 @@ #ifndef __FTPixmapGlyph__ #define __FTPixmapGlyph__ +#include "FTGL.h" + #include #include FT_FREETYPE_H #include FT_GLYPH_H @@ -8,25 +10,56 @@ #include "FTGlyph.h" -class FTPixmapGlyph : public FTGlyph +/** + * FTPixmapGlyph is a specialisation of FTGlyph for creating pixmaps. + * + * @see FTGlyphContainer + * + */ +class FTGL_EXPORT FTPixmapGlyph : public FTGlyph { public: - // methods + /** + * Constructor + * + * @param glyph The Freetype glyph to be processed + */ FTPixmapGlyph( FT_Glyph glyph); + + /** + * Destructor + */ virtual ~FTPixmapGlyph(); + + /** + * Renders this glyph at the current pen position. + * + * @param pen The current pen position. + * @return The advance distance for this glyph. + */ virtual float Render( const FT_Vector& pen); // attributes private: - // methods - - // attributes + /** + * The width of the glyph 'image' + */ int destWidth; + + /** + * The height of the glyph 'image' + */ int destHeight; + /** + * The number of greys or bit depth of the image + */ int numGreys; + /** + * Pointer to the 'image' data + */ unsigned char* data; }; diff --git a/src/osgText/FTPolyGlyph.cpp b/src/osgText/FTPolyGlyph.cpp index f400bbecd..1c31f3143 100644 --- a/src/osgText/FTPolyGlyph.cpp +++ b/src/osgText/FTPolyGlyph.cpp @@ -1,10 +1,8 @@ -#include "GL/gl.h" -#include "GL/glu.h" #include "FTPolyGlyph.h" #include "FTVectoriser.h" -#include "FTGL.h" +#include "GL/glu.h" #ifndef CALLBACK #define CALLBACK diff --git a/src/osgText/FTPolyGlyph.h b/src/osgText/FTPolyGlyph.h index 7682fcda2..c49d1c466 100644 --- a/src/osgText/FTPolyGlyph.h +++ b/src/osgText/FTPolyGlyph.h @@ -1,6 +1,8 @@ #ifndef __FTPolyGlyph__ #define __FTPolyGlyph__ +#include "FTGL.h" + #include #include FT_FREETYPE_H #include FT_GLYPH_H @@ -9,30 +11,83 @@ class FTVectoriser; -class FTPolyGlyph : public FTGlyph +/** + * FTPolyGlyph is a specialisation of FTGlyph for creating tessellated + * polygon glyphs. + * + * @see FTGlyphContainer + * @see FTVectoriser + * + */ +class FTGL_EXPORT FTPolyGlyph : public FTGlyph { public: - // methods + /** + * Constructor + * + * @param glyph The Freetype glyph to be processed + */ FTPolyGlyph( FT_Glyph glyph); + + /** + * Destructor + */ virtual ~FTPolyGlyph(); + + /** + * Renders this glyph at the current pen position. + * + * @param pen The current pen position. + * @return The advance distance for this glyph. + */ virtual float Render( const FT_Vector& pen); - // attributes - private: - // methods + /** + * Convert the point data into a mesh. + * + * Uses GLUtesselator to create a mesh + */ void Tesselate(); - // attributes + /** + * An object that helps convert freetype outlines into point + * data + */ FTVectoriser* vectoriser; + + /** + * The total number of points in the Freetype outline + */ int numPoints; + + /** + * The totals number of contours in the Freetype outline + */ int numContours; + + /** + * An flag indicating the tesselation rules for this glyph + */ int contourFlag; + + /** + * An array containing the number of points in each outline + */ int* contourLength; + + /** + * Pointer to the point data + */ double* data; + + /** + * OpenGL display list + */ int glList; }; #endif // __FTPolyGlyph__ + diff --git a/src/osgText/FTSize.h b/src/osgText/FTSize.h index 774c8d95e..e58609270 100644 --- a/src/osgText/FTSize.h +++ b/src/osgText/FTSize.h @@ -1,10 +1,11 @@ #ifndef __FTSize__ #define __FTSize__ +#include "FTGL.h" + #include #include FT_FREETYPE_H -#include "FTGL.h" /** @@ -13,7 +14,7 @@ * @see "Freetype 2 Documentation - 2.0.4" * */ -class FTSize +class FTGL_EXPORT FTSize { public: /** @@ -116,3 +117,4 @@ class FTSize }; #endif // __FTSize__ + diff --git a/src/osgText/FTTextureGlyph.cpp b/src/osgText/FTTextureGlyph.cpp index d15f8787d..8e17b9e28 100644 --- a/src/osgText/FTTextureGlyph.cpp +++ b/src/osgText/FTTextureGlyph.cpp @@ -1,5 +1,3 @@ -#include "GL/gl.h" - #include "FTTextureGlyph.h" #include "FTGL.h" @@ -90,3 +88,4 @@ float FTTextureGlyph::Render( const FT_Vector& pen) return advance; } + diff --git a/src/osgText/FTTextureGlyph.h b/src/osgText/FTTextureGlyph.h index bac8d4c9c..ab6fd5dba 100644 --- a/src/osgText/FTTextureGlyph.h +++ b/src/osgText/FTTextureGlyph.h @@ -1,6 +1,7 @@ #ifndef __FTTextureGlyph__ #define __FTTextureGlyph__ +#include "FTGL.h" #include #include FT_FREETYPE_H @@ -9,30 +10,85 @@ #include "FTGlyph.h" -class FTTextureGlyph : public FTGlyph +/** + * FTTextureGlyph is a specialisation of FTGlyph for creating texture + * glyphs. + * + * @see FTGlyphContainer + * + */ +class FTGL_EXPORT FTTextureGlyph : public FTGlyph { public: - // methods + /** + * Constructor + * + * @param glyph The Freetype glyph to be processed + * @param id The index of the texture that this glyph will + * be drawn in + * @param data A pointer to the texture memory + * @param stride The stride of the texture memory + * @param height The height (number of rows) of the texture memory + * @param u The texture co-ord for this glyph + * @param v The texture co-ord for this glyph + */ FTTextureGlyph( FT_Glyph glyph, int id, unsigned char* data, int stride, int height, float u, float v); + + /** + * Destructor + */ virtual ~FTTextureGlyph(); + + /** + * Renders this glyph at the current pen position. + * + * @param pen The current pen position. + * @return The advance distance for this glyph. + */ virtual float Render( const FT_Vector& pen); + /** + * The texture index of the currently active texture + * + * Because a a full set of glyphs may not fit on one glyph we need + * to keep track of the current active texture to try to reduce the + * number of texture bind operations + */ static int activeTextureID; + private: - // attributes - // What about the other point class in vectoriser? + /** + * The width of the glyph 'image' + */ + int destWidth; + + /** + * The height of the glyph 'image' + */ + int destHeight; + + /** + * The number of greys or bit depth of the image + */ + int numGreys; + + /** + * A structure to hold the uv co-ords. + */ struct FTPoint { float x; float y; }; - int destWidth; - int destHeight; - - int numGreys; - + /** + * The texture co-ords of this glyph within the texture. + */ FTPoint uv[2]; + + /** + * The texture index that this glyph is contained in. + */ int glTextureID; }; diff --git a/src/osgText/FTVectorGlyph.cpp b/src/osgText/FTVectorGlyph.cpp new file mode 100644 index 000000000..975be93fc --- /dev/null +++ b/src/osgText/FTVectorGlyph.cpp @@ -0,0 +1,87 @@ +#include "GL/gl.h" + +#include "FTVectorGlyph.h" +#include "FTVectoriser.h" +#include "FTGL.h" + + + +FTVectorGlyph::FTVectorGlyph( FT_Glyph glyph) +: FTGlyph(), + vectoriser(0), + numPoints(0), + numContours(0), + contourLength(0), + data(0), + glList(0) +{ + if( ft_glyph_format_outline != glyph->format) + { + return; + } + + vectoriser = new FTVectoriser( glyph); + + 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); + + advance = glyph->advance.x >> 16; + + delete vectoriser; + + if ( ( numContours < 1) || ( numPoints < 3)) + return; + + glList = glGenLists(1); + int d = 0; + + glNewList( glList, GL_COMPILE); + for( int c = 0; c < numContours; ++c) + { + glBegin( GL_LINE_LOOP); + for( int p = 0; p < ( contourLength[c]); ++p) + { + glVertex2dv( data + d); + d += 3; + } + glEnd(); + } + glEndList(); + + // discard glyph image (bitmap or not) + FT_Done_Glyph( glyph); // Why does this have to be HERE +} + + +FTVectorGlyph::~FTVectorGlyph() +{ + delete [] data; + delete [] contourLength; +} + + +float FTVectorGlyph::Render( const FT_Vector& pen) +{ + if( glList) + { + glTranslatef( pen.x, pen.y, 0); + glCallList( glList); + glTranslatef( -pen.x, -pen.y, 0); + } + + return advance; +} + + + + diff --git a/src/osgText/FTVectorGlyph.h b/src/osgText/FTVectorGlyph.h new file mode 100644 index 000000000..560d7a1a5 --- /dev/null +++ b/src/osgText/FTVectorGlyph.h @@ -0,0 +1,36 @@ +#ifndef __FTVectorGlyph__ +#define __FTVectorGlyph__ + +#include +#include FT_FREETYPE_H +#include FT_GLYPH_H + +#include "FTGlyph.h" + +class FTVectoriser; + +class FTVectorGlyph : public FTGlyph +{ + public: + // methods + FTVectorGlyph( FT_Glyph glyph); + virtual ~FTVectorGlyph(); + virtual float Render( const FT_Vector& pen); + + // attributes + + private: + // methods + + // attributes + FTVectoriser* vectoriser; + int numPoints; + int numContours; + int* contourLength; + double* data; + int glList; + +}; + + +#endif // __FTVectorGlyph__ diff --git a/src/osgText/FTVectoriser.h b/src/osgText/FTVectoriser.h index fb2d8b660..76ac6234d 100644 --- a/src/osgText/FTVectoriser.h +++ b/src/osgText/FTVectoriser.h @@ -1,6 +1,8 @@ #ifndef __FTVectoriser__ #define __FTVectoriser__ +#include "FTGL.h" + #include #include @@ -11,91 +13,253 @@ using namespace std; -class ftPoint +/** + * ftPoint class is a basic 3 dimensional point for holding outline font + * point data. + * + * @see FTOutlineGlyph + * @see FTPolyGlyph + * + */ +class FTGL_EXPORT ftPoint { public: + /** + * Default constructor. Point is set to zero. + */ ftPoint() : x(0), y(0), z(0) {} + /** + * Constructor. + * + * @param X + * @param Y + * @param Z + */ ftPoint( const float X, const float Y, const float Z) : x(X), y(Y), z(Z) {} + /** + * Operator == Tests for eqaulity + * + * @param a + * @param b + * @return + */ friend bool operator == ( const ftPoint &a, const ftPoint &b) { return((a.x == b.x) && (a.y == b.y) && (a.z == b.z)); } + /** + * Operator != Tests for non equality + * + * @param a + * @param b + * @return + */ friend bool operator != ( const ftPoint &a, const ftPoint &b) { return((a.x != b.x) || (a.y != b.y) || (a.z != b.z)); } + /** + * The point data + */ float x, y, z; // FIXME make private private: }; -class FTContour +/** + * ftPoint class is a container of points that describe an outline + * point data. + * + * @see FTOutlineGlyph + * @see FTPolyGlyph + * @see ftPoint + * + */ +class FTGL_EXPORT FTContour { public: - // methods + /** + * Default constructor + */ FTContour(); + + /** + * Destructor + */ ~FTContour(); + /** + * Add a point to the end of this contour. + * + * Doesn't add the point if it's already on the end or the start + * of the contour. The Z component is always 0 + * + * @param x The X component of the point + * @param y The Y component of the point + */ void AddPoint( const float x, const float y); + /** + * How many points define this contour + * + * @return the number of points in this contour + */ int size() const { return pointList.size();} - // attributes + /** + * The list of points in this contour + */ vector< ftPoint> pointList; - float ctrlPtArray[4][2]; private: - // methods - - // attributes + /** + * A 'max' number of points that this contour hods. Note it can + * hold more than this number. + */ const unsigned int kMAXPOINTS; }; -class FTVectoriser +/** + * FTVectoriser class is a helper class that converts font outlines into + * point data. It includes a bezier curve evaluator + * + * @see FTOutlineGlyph + * @see FTPolyGlyph + * @see FTContour + * @see ftPoint + * + */ +class FTGL_EXPORT FTVectoriser { public: - // methods + /** + * Constructor + * + * @param glyph The freetype glyph to be processed + */ FTVectoriser( FT_Glyph glyph); + + /** + * Destructor + */ virtual ~FTVectoriser(); - + + /** + * Process the freetype outline data into contours of points + * + * @return true on success + */ bool Ingest(); + + /** + * Copy the point data into a block of doubles + * @param d + */ void Output( double* d); + + /** + * Get the total count of points in this outline + * + * @return the number of points + */ int points(); + + /** + * Get the count of contours in this outline + * + * @return the number of contours + */ int contours() const { return contourList.size();} + + /** + * Get the nuber of points in a contour in this outline + * + * @param c The contour index + * @return the number of points in contour[c] + */ int contourSize( int c) const { return contourList[c]->size();} + + /** + * Get the flag for the tesselation rule for this outline + * + * @return The contour flag + */ int ContourFlag() const { return contourFlag;} - // attributes - private: - // methods + /** + * Process a conic ( second order bezier curve) + * + * @param index The index of the current point in the point list. + * @param first The index into the pointlist of the first point in + * the contour that the current point is part of. + * @param last The index into the pointlist of the last point in + * the contour that the current point is part of. + * @return the number of control points processed + */ int Conic( const int index, const int first, const int last); + + /** + * Process a cubic ( third order) bezier curve + * + * @param index The index of the current point in the point list. + * @param first The index into the pointlist of the first point in + * the contour that the current point is part of. + * @param last The index into the pointlist of the last point in + * the contour that the current point is part of. + * @return the number of control points processed + */ int Cubic( const int index, const int first, const int last); + + /** + * @param a + * @param b + */ void deCasteljau( const float t, const int n); + + /** + * @param a + */ void evaluateCurve( const int n); - // attributes + /** + * The list of contours in this outline + */ vector< const FTContour*> contourList; + /** + * A temporary FTContour + */ FTContour* contour; + + /** + * A flag indicating the tesselation rule for this outline + */ int contourFlag; + /** + * A Freetype outline + */ FT_Outline ftOutline; + /** + */ // Magic numbers -- #define MAX_DEG 4 float bValues[4][4][2]; //3D array storing values of de Casteljau algorithm. float ctrlPtArray[4][2]; // Magic numbers + /** + */ const float kBSTEPSIZE; }; diff --git a/src/osgText/Makefile b/src/osgText/Makefile index 94fcc7385..12c908ab0 100644 --- a/src/osgText/Makefile +++ b/src/osgText/Makefile @@ -20,6 +20,7 @@ C++FILES = \ FTGLBitmapFont.cpp \ FTGlyph.cpp \ FTPolyGlyph.cpp \ + FTVectorGlyph.cpp \ Text.cpp \ Version.cpp @@ -38,7 +39,7 @@ TARGET_INCLUDE_FILES = \ osgText/Version\ osgText/Text -C++FLAGS += -I ../../include -I /usr/local/include/freetype2 +C++FLAGS += -I ../../include -I /usr/include/freetype2 -I /usr/local/include/freetype2 include ../../Make/makerules