Added code to calculate the min texture size
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
diff --git a/src/FTGLTextureFont.cpp b/src/FTGLTextureFont.cpp
index 9ecff8b..00bc564 100755
--- a/src/FTGLTextureFont.cpp
+++ b/src/FTGLTextureFont.cpp
@@ -27,11 +27,7 @@ FTGLTextureFont::FTGLTextureFont()
: glTextureID(0),
textMem(0),
padding(15)
-{
-// glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxTextSize);
-// glGenTextures( 1, &glTextureID);
-
-}
+{}
FTGLTextureFont::~FTGLTextureFont()
@@ -60,32 +56,32 @@ bool FTGLTextureFont::MakeGlyphList()
for( int n = 0; n <= numGlyphs; ++n)
{
- glyphIndex = FT_Get_Char_Index( *ftFace, n);
-
- err = FT_Load_Glyph( *ftFace, glyphIndex, FT_LOAD_DEFAULT);
- if( err)
- { }
+ 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)
+ {}
- FT_Glyph ftGlyph;
-
- err = FT_Get_Glyph( (*ftFace)->glyph, &ftGlyph);
- if( err)
- {}
+ unsigned char* data = textMem + ( ( currentTextY * textureSize) + currentTextX);
- unsigned char* data = textMem + ( ( currentTextY * textureSize) + currentTextX);
-
- currTextU = (float)currentTextX / (float)textureSize;
-
- tempGlyph = new FTTextureGlyph( ftGlyph, glyphIndex, data, textureSize, currTextU, currTextV);
- glyphList->Add( tempGlyph);
-
- currentTextX += glyphWidth;
- if( currentTextX > ( textureSize - glyphWidth))
- {
- currentTextY += glyphHeight;
- currentTextX = padding;
- currTextV = (float)currentTextY / (float)textureSize;
- }
+ currTextU = (float)currentTextX / (float)textureSize;
+
+ tempGlyph = new FTTextureGlyph( ftGlyph, glyphIndex, data, textureSize, currTextU, currTextV);
+ glyphList->Add( tempGlyph);
+
+ currentTextX += glyphWidth;
+ if( currentTextX > ( textureSize - glyphWidth))
+ {
+ currentTextY += glyphHeight;
+ currentTextX = padding;
+ currTextV = (float)currentTextY / (float)textureSize;
+ }
}
@@ -110,20 +106,18 @@ bool FTGLTextureFont::CreateTexture()
glyphHeight = ( charSize.Height()) + padding;
glyphWidth = ( charSize.Width()) + padding;
- // calc the smallest texture size to fit the glyphs
-//FIXME
-// x * y
-// o = --------
-// x + y
-// int x = glyphWidth * numGlyphs;
-// int y = glyphHeight * numGlyphs;
-
-// int o = ( x * y) / ( x + y);
+ //FIXME
+// textureSize = 1024;
+ int t;
+ for( t = 64; t <= maxTextSize; t *=2)
+ {
+ int h = static_cast<int>( t / glyphWidth);
+ if( t > ( ( numGlyphs / h) * glyphHeight))
+ break;
+ }
-// textureSize = NextPowerOf2( o);
+ textureSize = t;
- textureSize = 1024;
-
horizGlyphs = static_cast<int>( textureSize / glyphWidth);
vertGlyphs = static_cast<int>(( numGlyphs / horizGlyphs) + 1);
@@ -137,26 +131,11 @@ bool FTGLTextureFont::CreateTexture()
bool FTGLTextureFont::render( const char* string)
-{
- char* c = string;
- FT_Vector kernAdvance;
- pen.x = 0; pen.y = 0;
-
+{
glBindTexture( GL_TEXTURE_2D, glTextureID);
- glBegin( GL_QUADS);
- while( *c)
- {
- kernAdvance = glyphList->render( *c, *(c + 1), pen);
-
- pen.x += kernAdvance.x;
- pen.y += kernAdvance.y;
-
- ++c;
- }
-
+ // QUADS are faster!? Less function call overhead?
+ glBegin( GL_QUADS);
+ FTFont::render( string);
glEnd();
}
-
-
-