Skip to content

Instantly share code, notes, and snippets.

@deephack1982
Created September 10, 2019 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deephack1982/e203c50738968a7c69291f2cdae6b83f to your computer and use it in GitHub Desktop.
Save deephack1982/e203c50738968a7c69291f2cdae6b83f to your computer and use it in GitHub Desktop.
////////////////////////
// pdx_fontatlas.h
////////////////////////
struct SFontGlyph
{
SFontGlyph(CRect<int> GlyphRect) : Rect(GlyphRect) { }
CRect<int> Rect;
};
class CPdxFontAtlas : public CRefCountedObject
{
public:
CPdxFontAtlas(CPdxFont* pFont, int nWidth = 2048, int nHeight = 2048);
~CPdxFontAtlas();
bool AddCharacters(char* characters);
SFontGlyph* GetGlyph(char c) { return m_Glyphs[c]; }
private:
CPdxFont* m_Font;
CPdxTextureAtlas* m_Texture;
SFontGlyph* m_Glyphs[256];
};
////////////////////////
// pdx_fontatlas.cpp
////////////////////////
CPdxFontAtlas::CPdxFontAtlas( CPdxFont* pFont, int nWidth, int nHeight )
{
m_Font = pFont;
m_Texture = new CPdxTextureAtlas(nWidth, nHeight);
}
CPdxFontAtlas::~CPdxFontAtlas()
{
delete m_Texture;
}
bool CPdxFontAtlas::AddCharacters(char* characters)
{
int j = 0;
while(j < strlen(characters))
{
CRect<int> GlyphRect;
bool Result = m_Font->AddGlyphToTexture(m_Texture, characters[j], GlyphRect);
m_Glyphs[characters[j++]] = new SFontGlyph(GlyphRect);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment