Skip to content

Commit

Permalink
#2: Font API requires asset manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruskiy69 committed Jul 12, 2013
1 parent 6a42fe6 commit 4a7dc28
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 13 additions & 1 deletion include/Zenderer/GUI/Font.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,16 @@ namespace gui
/// Clears the internal string stream.
void ClearString();

void AttachManager(asset::CAssetManager& Assets);
void AttachManager(asset::CAssetManager& Assets)
{
mp_Assets = &Assets;
}

private:
bool Destroy();
bool LoadGlyph(const char c, const uint32_t index);

asset::CAssetManager* mp_Assets;
color4f_t m_Color;
FT_Face m_FontFace;

Expand All @@ -156,6 +160,11 @@ namespace gui
* themselves into `obj::CEntity` instances that can then be treated as
* such.
*
* @note It is absolutely essential that you call `AttachManager()` prior
* to loading any font instances, to ensure that the font textures
* can be created. This is a limitation of the asset API and may or
* may not change in the future.
*
* @example Fonts
* @section Font Rendering Examples
* @subsection Rendering With a Scene
Expand All @@ -172,6 +181,9 @@ namespace gui
*
* // Error checking omitted for brevity.
*
* // REQUIRED!
* Font->AttachManager(Assets);
*
* // Render a string to an entity
* obj::CEntity& Score = Scene.AddEntity();
* Font->Render(Score, "Score: 0");
Expand Down
3 changes: 2 additions & 1 deletion src/GUI/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ void CFont::ClearString()

bool CFont::LoadGlyph(const char c, const uint32_t index)
{
ZEN_ASSERTM(mp_Assets != nullptr, "an asset manager must be attached");
FT_Glyph g;

// Render as a monochrome bitmap into glyph struct.
Expand All @@ -259,7 +260,7 @@ bool CFont::LoadGlyph(const char c, const uint32_t index)
GL(glGetIntegerv(GL_UNPACK_ALIGNMENT, &pack));
GL(glPixelStorei(GL_UNPACK_ALIGNMENT, 1))

gfxcore::CTexture* pTexture = m_Assets.Create<gfxcore::CTexture>(this->GetOwner());
gfxcore::CTexture* pTexture = mp_Assets->Create<gfxcore::CTexture>(this->GetOwner());
pTexture->LoadFromRaw(GL_R8, GL_RED, w, h, bitmap.buffer);

GL(glPixelStorei(GL_UNPACK_ALIGNMENT, pack));
Expand Down

0 comments on commit 4a7dc28

Please sign in to comment.