Commit f29956a1067945a0d81b56ebc3df764fdfe477f1

henry 2003-04-13T02:09:47

Fixed FTGLTextureFont resize bug

diff --git a/include/FTFont.h b/include/FTFont.h
index 3f36839..b91acb4 100755
--- a/include/FTFont.h
+++ b/include/FTFont.h
@@ -90,7 +90,7 @@ class FTGL_EXPORT FTFont
          * @param res       the resolution of the target device.
          * @return          <code>true</code> if size was set correctly
          */
-        bool FaceSize( const unsigned int size, const unsigned int res = 72);
+        virtual bool FaceSize( const unsigned int size, const unsigned int res = 72);
         
         /**
          * Get the current face size in points.
diff --git a/include/FTGLTextureFont.h b/include/FTGLTextureFont.h
index 7196884..ff42e3f 100755
--- a/include/FTGLTextureFont.h
+++ b/include/FTGLTextureFont.h
@@ -35,17 +35,16 @@ class  FTGL_EXPORT FTGLTextureFont : public FTFont
          * Destructor
          */
         virtual ~FTGLTextureFont();
-        
-        /**
-         * Get the total width of the texture that holds this font
-         */
-        GLsizei TextureWidth() const { return textureWidth;}
-        
+
         /**
-         * Get the total height of the texture that holds this font
+            * Set the char size for the current face.
+         *
+         * @param size      the face size in points (1/72 inch)
+         * @param res       the resolution of the target device.
+         * @return          <code>true</code> if size was set correctly
          */
-        GLsizei TextureHeight() const { return textureHeight;}
-        
+        virtual bool FaceSize( const unsigned int size, const unsigned int res = 72);
+
         /**
          * Renders a string of characters
          * 
@@ -116,12 +115,6 @@ class  FTGL_EXPORT FTGLTextureFont : public FTFont
         unsigned int numTextures;
 
         /**
-         * The memory where the textures are built before being transferred 
-         * to OpenGL
-         */
-        unsigned char* textMem;
-        
-        /**
          * The max height for glyphs in the current font
          */
         int glyphHeight;
diff --git a/src/FTFace.cpp b/src/FTFace.cpp
index 06dcd53..42f7d58 100755
--- a/src/FTFace.cpp
+++ b/src/FTFace.cpp
@@ -149,17 +149,19 @@ FTPoint FTFace::KernAdvance( unsigned int index1, unsigned int index2)
 
 FT_Glyph* FTFace::Glyph( unsigned int index, FT_Int load_flags)
 {
-    err = FT_Load_Glyph( *ftFace, index, load_flags);   
-    err = FT_Get_Glyph( (*ftFace)->glyph, &ftGlyph);
-        
-    if( !err)
+    err = FT_Load_Glyph( *ftFace, index, load_flags);
+    if( err)
     {
-        return &ftGlyph;
+        return NULL;
     }
-    else
+    
+    err = FT_Get_Glyph( (*ftFace)->glyph, &ftGlyph);
+    if( err)
     {
         return NULL;
     }
+
+    return &ftGlyph;
 }
 
 
diff --git a/src/FTGLTextureFont.cpp b/src/FTGLTextureFont.cpp
index 902e2e2..ec72a20 100755
--- a/src/FTGLTextureFont.cpp
+++ b/src/FTGLTextureFont.cpp
@@ -1,7 +1,7 @@
-#include    <string>
+#include <string> // For memset
 
-#include    "FTGLTextureFont.h"
-#include    "FTTextureGlyph.h"
+#include "FTGLTextureFont.h"
+#include "FTTextureGlyph.h"
 
 
 inline GLuint NextPowerOf2( GLuint in)
@@ -24,7 +24,6 @@ FTGLTextureFont::FTGLTextureFont( const char* fontname)
     textureWidth(0),
     textureHeight(0),
     numTextures(0),
-    textMem(0),
     glyphHeight(0),
     glyphWidth(0),
     padding(3),
@@ -41,7 +40,6 @@ FTGLTextureFont::FTGLTextureFont( const unsigned char *pBufferBytes, size_t buff
     textureWidth(0),
     textureHeight(0),
     numTextures(0),
-    textMem(0),
     glyphHeight(0),
     glyphWidth(0),
     padding(3),
@@ -125,9 +123,9 @@ GLuint FTGLTextureFont::CreateTexture()
 {   
     CalculateTextureSize();
     
-    int totalMem = textureWidth * textureHeight;
-    textMem = new unsigned char[totalMem];
-    memset( textMem, 0, totalMem);
+    int totalMemory = textureWidth * textureHeight;
+    unsigned char* textureMemory = new unsigned char[totalMemory];
+    memset( textureMemory, 0, totalMemory);
 
     GLuint textID;
     glGenTextures( 1, (GLuint*)&textID);
@@ -138,14 +136,27 @@ GLuint FTGLTextureFont::CreateTexture()
     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 
-    glTexImage2D( GL_TEXTURE_2D, 0, GL_ALPHA, textureWidth, textureHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, textMem);
+    glTexImage2D( GL_TEXTURE_2D, 0, GL_ALPHA, textureWidth, textureHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, textureMemory);
 
-    delete [] textMem;
+    delete [] textureMemory;
 
     return textID;
 }
 
 
+bool FTGLTextureFont::FaceSize( const unsigned int size, const unsigned int res)
+{
+    if( numTextures)
+    {
+        glDeleteTextures( numTextures, (const GLuint*)glTextureID);
+        numTextures = 0;
+        remGlyphs = numGlyphs = face.GlyphCount();
+    }
+
+    return FTFont::FaceSize( size, res);
+}
+
+
 void FTGLTextureFont::Render( const char* string)
 {   
     glPushAttrib( GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT);