Reformatted and merged with 1.32
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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
diff --git a/src/FTGLTextureFont.cpp b/src/FTGLTextureFont.cpp
index 512422b..5724c05 100755
--- a/src/FTGLTextureFont.cpp
+++ b/src/FTGLTextureFont.cpp
@@ -1,7 +1,7 @@
-#include "FTGLTextureFont.h"
-#include "FTTextureGlyph.h"
+#include "FTGLTextureFont.h"
+#include "FTTextureGlyph.h"
#ifdef FTGL_DEBUG
- #include "mmgr.h"
+ #include "mmgr.h"
#endif
@@ -23,156 +23,157 @@ inline GLuint NextPowerOf2( GLuint in)
FTGLTextureFont::FTGLTextureFont()
-: maxTextSize(0),
- textureWidth(0),
- textureHeight(0),
- numTextures(0),
- textMem(0),
- glyphHeight(0),
- glyphWidth(0),
- padding(1),
- remGlyphs(0),
- xOffset(0),
- yOffset(0)
+: maxTextSize(0),
+ textureWidth(0),
+ textureHeight(0),
+ numTextures(0),
+ textMem(0),
+ glyphHeight(0),
+ glyphWidth(0),
+ padding(1),
+ remGlyphs(0),
+ xOffset(0),
+ yOffset(0)
{}
FTGLTextureFont::~FTGLTextureFont()
{
- glDeleteTextures( numTextures, (const GLuint*)glTextureID);
+ glDeleteTextures( numTextures, (const GLuint*)glTextureID);
}
FTGlyph* FTGLTextureFont::MakeGlyph( unsigned int g)
{
- FT_Glyph* ftGlyph = face.Glyph( g, FT_LOAD_NO_HINTING);
-
- if( ftGlyph)
- {
- // Estimate the glyph size size - global bbox
- glyphHeight = ( charSize.Height());
- glyphWidth = ( charSize.Width());
-
- // Is there a current texture
- if( numTextures == 0)
- {
- glTextureID[0] = CreateTexture();
- xOffset = yOffset = padding;
- ++numTextures;
- }
-
- // will it fit in the current texture
- if( xOffset > ( textureWidth - glyphWidth))
- {
- xOffset = padding;
- yOffset += glyphHeight;
-
- if( yOffset > ( textureHeight - glyphHeight))
- {
- // no - make a new texture
- glTextureID[numTextures] = CreateTexture();
- yOffset = padding;
- ++numTextures;
- }
- }
-
- // yes - load the glyph
- FTTextureGlyph* tempGlyph = new FTTextureGlyph( *ftGlyph, glTextureID[numTextures - 1],
- xOffset, yOffset, textureWidth, textureHeight);
-
- xOffset += tempGlyph->BBox().x2 - tempGlyph->BBox().x1 + padding;
-
- --remGlyphs;
+ FT_Glyph* ftGlyph = face.Glyph( g, FT_LOAD_NO_HINTING);
+
+ if( ftGlyph)
+ {
+ // Estimate the glyph size size - global bbox
+ glyphHeight = ( charSize.Height());
+ glyphWidth = ( charSize.Width());
+
+ // Is there a current texture
+ if( numTextures == 0)
+ {
+ glTextureID[0] = CreateTexture();
+ xOffset = yOffset = padding;
+ ++numTextures;
+ }
+
+ // will it fit in the current texture
+ if( xOffset > ( textureWidth - glyphWidth))
+ {
+ xOffset = padding;
+ yOffset += glyphHeight;
+
+ if( yOffset > ( textureHeight - glyphHeight))
+ {
+ // no - make a new texture
+ glTextureID[numTextures] = CreateTexture();
+ yOffset = padding;
+ ++numTextures;
+ }
+ }
+
+ // yes - load the glyph
+ FTTextureGlyph* tempGlyph = new FTTextureGlyph( *ftGlyph, glTextureID[numTextures - 1],
+ xOffset, yOffset, textureWidth, textureHeight);
+
+ // FIXME ceiling
+ xOffset += tempGlyph->BBox().x2 - tempGlyph->BBox().x1 + padding;
+
+ --remGlyphs;
// FT_Done_Glyph( *ftGlyph );
- return tempGlyph;
- }
-
- err = face.Error();
- return NULL;
+ return tempGlyph;
+ }
+
+ err = face.Error();
+ return NULL;
}
bool FTGLTextureFont::MakeGlyphList()
{
- if( !maxTextSize)
- glGetIntegerv( GL_MAX_TEXTURE_SIZE, (GLint*)&maxTextSize);
+ if( !maxTextSize)
+ glGetIntegerv( GL_MAX_TEXTURE_SIZE, (GLint*)&maxTextSize);
- remGlyphs = numGlyphs;
+ remGlyphs = numGlyphs;
- FTFont::MakeGlyphList();
-
- return !err; // FIXME what err?
+ FTFont::MakeGlyphList();
+
+ return !err; // FIXME what err?
}
void FTGLTextureFont::GetSize()
{
- //work out the max width. Most likely maxTextSize
- textureWidth = NextPowerOf2( (remGlyphs * glyphWidth) + padding * 2);
- if( textureWidth > maxTextSize)
- {
- textureWidth = maxTextSize;
- }
-
- int h = static_cast<int>( (textureWidth - padding * 2) / glyphWidth);
+ //work out the max width. Most likely maxTextSize
+ textureWidth = NextPowerOf2( (remGlyphs * glyphWidth) + padding * 2);
+ if( textureWidth > maxTextSize)
+ {
+ textureWidth = maxTextSize;
+ }
+
+ int h = static_cast<int>( (textureWidth - padding * 2) / glyphWidth);
- textureHeight = NextPowerOf2( (( numGlyphs / h) + 1) * glyphHeight);
- textureHeight = textureHeight > maxTextSize ? maxTextSize : textureHeight;
+ textureHeight = NextPowerOf2( (( numGlyphs / h) + 1) * glyphHeight);
+ textureHeight = textureHeight > maxTextSize ? maxTextSize : textureHeight;
}
int FTGLTextureFont::CreateTexture()
-{
- // calc the size
- GetSize();
-
- // allocate some mem and clear it to black
- int totalMem = textureWidth * textureHeight;
- textMem = new unsigned char[totalMem]; // GL_ALPHA texture;
- memset( textMem, 0, totalMem);
-
- // Create the blank texture
- int textID;
- glGenTextures( 1, (GLuint*)&textID);
-
- glPixelStorei( GL_UNPACK_ALIGNMENT, 1); //What does this do exactly?
- glBindTexture( GL_TEXTURE_2D, textID);
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- 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);
-
- delete [] textMem;
-
- return textID;
+{
+ // calc the size
+ GetSize();
+
+ // allocate some mem and clear it to black
+ int totalMem = textureWidth * textureHeight;
+ textMem = new unsigned char[totalMem]; // GL_ALPHA texture;
+ memset( textMem, 0, totalMem);
+
+ // Create the blank texture
+ int textID;
+ glGenTextures( 1, (GLuint*)&textID);
+
+ glPixelStorei( GL_UNPACK_ALIGNMENT, 1); //What does this do exactly?
+ glBindTexture( GL_TEXTURE_2D, textID);
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ 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);
+
+ delete [] textMem;
+
+ return textID;
}
void FTGLTextureFont::render( const char* string)
-{
- glPushAttrib( GL_ENABLE_BIT | GL_HINT_BIT | GL_LINE_BIT | GL_PIXEL_MODE_BIT);
-
- glEnable(GL_BLEND);
- glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
-
- FTFont::render( string);
-
- glPopAttrib();
+{
+ glPushAttrib( GL_ENABLE_BIT | GL_HINT_BIT | GL_LINE_BIT | GL_PIXEL_MODE_BIT);
+
+ glEnable(GL_BLEND);
+ glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
+
+ FTFont::render( string);
+
+ glPopAttrib();
}
void FTGLTextureFont::render( const wchar_t* string)
-{
- glPushAttrib( GL_ENABLE_BIT | GL_HINT_BIT | GL_LINE_BIT | GL_PIXEL_MODE_BIT);
-
- glEnable(GL_BLEND);
- glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
-
- FTFont::render( string);
-
- glPopAttrib();
+{
+ glPushAttrib( GL_ENABLE_BIT | GL_HINT_BIT | GL_LINE_BIT | GL_PIXEL_MODE_BIT);
+
+ glEnable(GL_BLEND);
+ glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
+
+ FTFont::render( string);
+
+ glPopAttrib();
}