/********************************************************************
*
* File: fsCFont.h
*
* Purpose: bgfx font implementation. Bakes a glyph atlas with
* stb_truetype into a bgfx texture at load time.
*
*********************************************************************/
#ifndef fsCFonthdr
#define fsCFonthdr
#include <map>
#include <memory>
#include <bgfx/bgfx.h>
#include "../../fsIFont.h"
class fsCFont : public fsIFont
{
friend class fsIFont;
friend class fsCRenderer;
friend class fsCNativeTextSprite;
public:
virtual ~fsCFont();<--- Destructor in derived class
protected:
void initialiseDo(const fsSFontParams& pParams) override;
fsCFont();
private:
struct fsSGlyph
{
// atlas rect in texels
fsF32 mX0 = 0;
fsF32 mY0 = 0;
fsF32 mX1 = 0;
fsF32 mY1 = 0;
// layout offsets relative to the baseline pen position
fsF32 mXOff = 0;
fsF32 mYOff = 0;
fsF32 mXAdvance = 0;
};
const fsSGlyph* glyphGet(fsS32 pCodepoint) const;
std::map<fsS32, fsSGlyph> mGlyphs;
bgfx::TextureHandle mTexture = BGFX_INVALID_HANDLE;
fsS32 mAtlasWidth = 0;
fsS32 mAtlasHeight = 0;
fsF32 mPointSize = 0;
fsF32 mAscent = 0;
fsF32 mLineHeight = 0;
};
#endif