Created
September 10, 2019 08:11
-
-
Save deephack1982/e203c50738968a7c69291f2cdae6b83f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////// | |
// 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