void BitmapFont::Build() { if (isBuilt) return; if (!LoadFontMap()) { psys->GetLogger("BitmapFont")->Error("Failed to load font map"); return; } for(int i=0; i<256; i++) { if (chardefs[i]->Used()) { BitmapCharDef *character = chardefs[i]; psys->GetLogger("BitmapFont")->Debug("Char '%c' (X:%d, Y:%d), (W:%d, H:%d)",i,character->X(), character->Y(), character->Width(), character->Height()); Bitmap *bmpChar = bitmap->CopyToNew(character->X(), character->Y(), character->Width(), character->Height()); FontChar *fc = new FontChar(i, 0, 0, bmpChar->Width(), bmpChar->Height(), bmpChar); //FontChar *fc = new FontChar(i, 0, 0, bitmap->Width(), bitmap->Height(), bitmap); fc->GenerateTexture(); AddChar(i, fc); } } isBuilt = true; }
void Font::BuildTexturesForString(std::string &string) { for (int i=0; i<string.length(); i++) { if (FT_Load_Char(face, string.at(i), FT_LOAD_RENDER)) continue; FT_GlyphSlot g = face->glyph; int character = string.at(i); Bitmap *bmp = new Bitmap(g->bitmap.width, g->bitmap.rows, g->bitmap.buffer); FontChar *fc = new FontChar(character, g->bitmap_left, g->bitmap_top, g->advance.x, g->advance.y, bmp); fc->GenerateTexture(); AddChar(character, fc); } }