86 void render(
const std::string& text,
float winAspect,
float height,
93 void render(uint32_t number,
float winAspect,
float height,
102 Vec2 getSize(
const std::string& text,
float winAspect,
float height)
const;
106 Vec2 getSize(uint32_t number,
float winAspect,
float height)
const;
118 this->renderAsSignedDistanceField = renderAsSignedDistanceField;
123 return renderAsSignedDistanceField;
131 bool renderAsSignedDistanceField;
152 const std::string& positionFilename);
156 const std::string& positionFilename);
160 const std::vector<CharPosition>& positions);
175 static const std::vector<CharPosition>
loadPositions(
const std::string& positionFilename);
181 std::string
toCode(
const std::string& varName)
const;
191 std::vector<CharPosition> positions;
Alignment
Text alignment modes used by the OpenGL renderer.
Definition FontRenderer.h:54
@ Center
Anchor centered around the position.
Definition FontRenderer.h:57
@ Right
Anchor on the right side.
Definition FontRenderer.h:56
@ Left
Anchor on the left side.
Definition FontRenderer.h:55
RAII wrapper for an OpenGL Vertex Array Object (VAO).
Thin RAII wrapper for an OpenGL buffer object with upload/binding helpers.
RAII wrapper for an OpenGL 2D texture with byte/half/float upload helpers.
2D scalar grid (float) with sampling, arithmetic, SDF, and I/O helpers.
Mat4t< float > Mat4
Single-precision 4×4 matrix.
Definition Mat4.h:567
2D vector template with arithmetic, length utilities, and helpers.
Vec2t< float > Vec2
Float vector (x,y).
Definition Vec2.h:258
Vec2t< uint32_t > Vec2ui
32-bit unsigned integer vector (x,y).
Definition Vec2.h:262
Vec4t< float > Vec4
4D float vector (x,y,z,w).
Definition Vec4.h:337
Minimal BMP I/O utilities and a region blit helper.
void render(const std::string &text, float winAspect, float height, const Vec2 &pos, Alignment a=Alignment::Center, const Vec4 &color=Vec4{1.0f, 1.0f, 1.0f, 1.0f})
Render a UTF-8 string.
Definition FontRenderer.cpp:235
FontEngine()
Create an empty engine and initialize shaders, quad geometry, and VBOs.
Definition FontRenderer.cpp:136
std::map< char, CharTex > sdChars
Per-character SDF textures + transforms.
Definition FontRenderer.h:114
bool getRenderAsSignedDistanceField() const
Current SDF rendering flag.
Definition FontRenderer.h:122
void renderFixedWidth(const std::string &text, float winAspect, float width, const Vec2 &pos, Alignment a=Alignment::Center, const Vec4 &color=Vec4{1.0f, 1.0f, 1.0f, 1.0f})
Render with fixed total width (height adapts to keep aspect).
Definition FontRenderer.cpp:321
Vec2 getSize(const std::string &text, float winAspect, float height) const
Expected on-screen size of text for a given height.
Definition FontRenderer.cpp:284
void setRenderAsSignedDistanceField(bool renderAsSignedDistanceField)
Enable/disable signed distance field rendering.
Definition FontRenderer.h:117
std::map< char, CharTex > chars
Per-character textures + transforms.
Definition FontRenderer.h:113
virtual ~FontEngine()
Definition FontRenderer.h:71
Vec2 getSizeFixedWidth(const std::string &text, float winAspect, float width) const
Expected on-screen size of text for a fixed width.
Definition FontRenderer.cpp:311
std::string getAllCharsString() const
Return the available characters as a single concatenated string.
Definition FontRenderer.cpp:362
std::string toCode(const std::string &varName) const
Emit C++ code to recreate the atlas image and positions vector.
Definition FontRenderer.cpp:89
FontRenderer(const std::string &imageFilename, const std::string &positionFilename)
Construct from filenames.
Definition FontRenderer.cpp:42
Image render(const std::string &text) const
Compose a new image containing text using the atlas glyphs.
Definition FontRenderer.cpp:66
static const std::vector< CharPosition > loadPositions(const std::string &positionFilename)
Load character rectangles from a text file.
Definition FontRenderer.cpp:14
std::shared_ptr< FontEngine > generateFontEngine() const
Create a GPU font engine initialized from this bitmap font.
Definition FontRenderer.cpp:106
OpenGL shader program with helpers for creation and data binding.
Definition GLProgram.h:59
Definition GLTexture2D.h:19
Character box in a bitmap atlas.
Definition FontRenderer.h:34
char c
Character this rectangle corresponds to.
Definition FontRenderer.h:35
Vec2ui topLeft
Top-left corner (inclusive) of the glyph box in the atlas.
Definition FontRenderer.h:36
Vec2ui bottomRight
Bottom-right corner (exclusive) of the glyph box in the atlas.
Definition FontRenderer.h:37
Texture + transform bundle for a single glyph used by FontEngine.
Definition FontRenderer.h:43
Mat4 trans
Per-glyph translation used by the renderer.
Definition FontRenderer.h:46
Mat4 scale
Per-glyph scale to normalize to [0,1] quad space.
Definition FontRenderer.h:45
GLTexture2D tex
Glyph texture (RGBA or single-channel).
Definition FontRenderer.h:44
float width
Glyph width normalized by the maximum glyph width in the set.
Definition FontRenderer.h:47
float height
Glyph height normalized by the maximum glyph height in the set.
Definition FontRenderer.h:48