Klyff text rendering
Klyff is a text rendering library designed for games with high customization needs, built on cosmic_text and wgpu.
It uses a technique called MSDF (Multi-channel Signed Distance Field), which supports infinite scaling while still retaining sharp corners (as opposed to SDF). MSDF generation is reimplemented in 100% pure Rust, instead of binding to the original msdfgen C++ library.
Features
- MSDF-based rendering - Glyphs scale infinitely without losing sharpness
- Rich text styling - Supports outline, glow (inner/outer), and shadow effects
- Gradient support - Linear gradients for text fill and effects
- GPU-accelerated MSDF generation - Generate distance fields directly on the GPU
- Rasterized glyph fallback - Colored emoji and bitmap glyphs render correctly
- Custom glyphs - Inject application-defined glyphs into text layout
- Atlas baking - Pre-generate glyph atlases offline for faster startup
- Pure Rust - No C/C++ dependencies for MSDF generation
Quick Start
use ;
// One-time setup
let mut renderer = new;
let mut atlas = new;
// Build styled text
let attrs = new.family;
let mut text_builder = new;
text_builder.push_text;
let text = text_builder.finish;
// Per frame: prepare and render
renderer.prepare;
let mut pass = encoder.begin_render_pass;
renderer.render;
API Layers
High-level API
Use TextRenderer and StyledText for quick setup with built-in styling support. Each styling effect (shadow, outline, glow) is rendered as a separate draw call in back-to-front order.
Low-level API
For custom shaders or advanced use cases:
MeshEncoder- Decodes text into vertex/index buffers and records per-glyph metadataMaterialEncoder- Produces per-glyph material data (colors, distance ranges, offsets)MsdfTextPipeline/RasterizedTextPipeline- Built-in render pipelines
License
All source code is licensed under the MIT License.