Updated FTGL version to 1.0 and removed a couple of warnings in the osgText demo.

This commit is contained in:
Robert Osfield
2001-10-24 09:41:42 +00:00
parent 6ddb40ba70
commit 5853215f1c
33 changed files with 921 additions and 158 deletions

View File

@@ -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;

View File

@@ -1,7 +1,4 @@
#include "GL/gl.h"
#include "FTBitmapGlyph.h"
#include "FTGL.h"
FTBitmapGlyph::FTBitmapGlyph( FT_Glyph glyph)

View File

@@ -1,6 +1,8 @@
#ifndef __FTBitmapGlyph__
#define __FTBitmapGlyph__
#include "FTGL.h"
#include <ft2build.h>
#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 <code>render</code> 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__

View File

@@ -1,6 +1,8 @@
#ifndef __FTCharmap__
#define __FTCharmap__
#include "FTGL.h"
#include <map>
#include <ft2build.h>
@@ -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;

View File

@@ -1,7 +1,7 @@
#ifndef __FTFace__
#define __FTFace__
//#include "FTGL.h"
#include "FTGL.h"
#include <ft2build.h>
#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 <code>true</code> if charmap was valid
* and set correctly

View File

@@ -3,6 +3,8 @@
#include <string>
#include "FTGL.h"
#include <ft2build.h>
#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__

View File

@@ -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 <GL/gl.h>
#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 <windows.h>
// to avoid name space pollution, but Win32's <GL/gl.h>
// needs APIENTRY and WINGDIAPI defined properly.
// F
# if 0
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# else
// XXX This is from Win32's <windef.h>
# 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 <winnt.h>
# 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 <wingdi.h> and <winnt.h>
# ifndef WINGDIAPI
# define GLUT_WINGDIAPI_DEFINED
# define WINGDIAPI __declspec(dllimport)
# endif
// XXX This is from Win32's <ctype.h>
# ifndef _WCHAR_T_DEFINED
typedef unsigned short wchar_t;
# define _WCHAR_T_DEFINED
# endif
# endif
#ifndef __gl_h_
#include <GL/gl.h>
#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__

View File

@@ -1,5 +1,3 @@
#include "GL/gl.h"
#include "FTGLBitmapFont.h"
#include "FTGlyphContainer.h"
#include "FTBitmapGlyph.h"

View File

@@ -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);

View File

@@ -1,5 +1,3 @@
#include "GL/gl.h"
#include "FTGLOutlineFont.h"
#include "FTGlyphContainer.h"
#include "FTGL.h"

View File

@@ -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__

View File

@@ -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();
}

View File

@@ -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__

View File

@@ -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__

View File

@@ -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();
}

View File

@@ -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__

View File

@@ -1,6 +1,8 @@
#ifndef __FTGlyph__
#define __FTGlyph__
#include "FTGL.h"
#include <ft2build.h>
#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__

View File

@@ -1,6 +1,8 @@
#ifndef __FTGlyphContainer__
#define __FTGlyphContainer__
#include "FTGL.h"
#include <vector>
#include <ft2build.h>
@@ -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<FTGlyph*> glyphs;
// typedef pair<int, FTGlyph*> CHARREF; // glyphIndex, glyph
// vector<CHARREF> glyphs;
// map< int, FTGlyph*> CHARREF; // charCode, glyph
/**
* Current error code. Zero means no error.
*/
FT_Error err;
};

View File

@@ -1,5 +1,4 @@
#include "FTLibrary.h"
#include "FTGL.h"
FTLibrary& FTLibrary::Instance()

View File

@@ -1,13 +1,12 @@
#ifndef __FTLibrary__
#define __FTLibrary__
#include "FTGL.h"
#include <ft2build.h>
#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.
*/

View File

@@ -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;
}

View File

@@ -1,6 +1,8 @@
#ifndef __FTOutlineGlyph__
#define __FTOutlineGlyph__
#include "FTGL.h"
#include <ft2build.h>
#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__

View File

@@ -1,5 +1,3 @@
#include "GL/gl.h"
#include "FTPixmapGlyph.h"
#include "FTGL.h"

View File

@@ -1,6 +1,8 @@
#ifndef __FTPixmapGlyph__
#define __FTPixmapGlyph__
#include "FTGL.h"
#include <ft2build.h>
#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;
};

View File

@@ -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

View File

@@ -1,6 +1,8 @@
#ifndef __FTPolyGlyph__
#define __FTPolyGlyph__
#include "FTGL.h"
#include <ft2build.h>
#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__

View File

@@ -1,10 +1,11 @@
#ifndef __FTSize__
#define __FTSize__
#include "FTGL.h"
#include <ft2build.h>
#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__

View File

@@ -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;
}

View File

@@ -1,6 +1,7 @@
#ifndef __FTTextureGlyph__
#define __FTTextureGlyph__
#include "FTGL.h"
#include <ft2build.h>
#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;
};

View File

@@ -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;
}

View File

@@ -0,0 +1,36 @@
#ifndef __FTVectorGlyph__
#define __FTVectorGlyph__
#include <ft2build.h>
#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__

View File

@@ -1,6 +1,8 @@
#ifndef __FTVectoriser__
#define __FTVectoriser__
#include "FTGL.h"
#include <vector>
#include <ft2build.h>
@@ -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 <code>true</code> on success
*/
bool Ingest();
/**
* Copy the point data into a block of <code>doubles</code>
* @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;
};

View File

@@ -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