VE Font Cache is a single header-only GPU font rendering library designed for game engines.

Related tags

Game VEFontCache
Overview

Logo

VE Font Cache is a single header-only GPU font rendering library designed for game engines.

It aims to:

  • Be fast and simple to integrate.
  • Take advantage of modern GPU power.
  • Be backend agnostic and easy to port to any API such as Vulkan, DirectX, OpenGL.
  • Load TTF & OTF file formats directly.
  • Use only runtime cache with no offline calculation.
  • Render glyphs at reasonable quality at a wide range of font sizes.
  • Support a good amount of internationalisation. そうですね!
  • Support cached text shaping with HarfBuzz with simple Latin-style fallback.
  • Load and unload fonts at any time.

How it works

Glyphs are GPU rasterised with 16x supersampling. This method is a simplification of "Easy Scalable Text Rendering on the GPU", by Evan Wallace, making use of XOR blending. Bézier curves are handled via brute force triangle tessellation; even 6 triangles per curve only generates < 300 triangles, which is nothing for modern GPUs! This avoids complex frag shader for reasonable quality.

Wireframe with GPU XOR blending

Texture atlas caching uses naïve grid placement; this wastes a lot of space but ensures interchangeable cache slots allowing for straight up LRU ( Least Recently Used ) caching scheme to be employed.

The font atlas is a single 4k x 2k R8 texture divided into 4 regions:

     2k
     --------------------
     |         |        |
     |    A    |        |
     |         |        | 2
     |---------|    C   | k  
     |         |        |
  1k |    B    |        |
     |         |        |
     --------------------
     |                  |
     |                  |
     |                  | 2
     |        D         | k  
     |                  |
     |                  |
     |                  |
     --------------------        
               
     Region A = 32x32 caches, 1024 glyphs
     Region B = 32x64 caches, 512 glyphs
     Region C = 64x64 caches, 512 glyphs
     Region D = 128x128 caches, 256 glyphs

Region A is designed for small glyphs, Region B is for tall glyphs, Region C is for large glyphs, and Region D for huge glyphs. Glyphs are first rendered to an intermediate 2k x 512px R8 texture. This allows for minimum 4 Region D glyphs supersampled at 4 x 4 = 16x supersampling, and 8 Region C glyphs similarly. A simple 16-tap box downsample shader is then used to blit from this intermediate texture to the final atlas location.

The atlas texture looks something like this: Wireframe with GPU XOR blending

Usage

Pseudo-code demonstrating simple usage:

#define VE_FONTCACHE_IMPL
#include "../ve_fontcache.h"

static std::vector< uint8_t > buffer;
ve_fontcache_init( &cache );
ve_fontcache_configure_snap( &cache, width, height );
print_font = ve_fontcache_loadfile( &cache, "fonts/NotoSansJP-Light.otf", buffer, 19.0f );
ve_fontcache_draw_text( &cache, print_font, u8"hello world", 0, 0, 1.0f / width,  1.0f / height );

These header files need to be copied to your project:

ve_fontcache.h
utf8.h
stb_truetype.h

Except HarfBuzz, that's all the required dependencies. That said it's strongly recommended to use HarfBuzz ( TODO: HarfBuzz not supported yet, coming soon!! ) over the default utf8.h latin fallback text shaper.

Integration with rendering backend

VEFontCache is largely backend agnostic. Currently the demo project uses OpenGL 3.3 for Windows. That said it's designed to be integrated with VE, a Vulkan engine. Please read the "How to plug into rendering API" section in ve_fontcache.h for more documentation on how to implement your own backend to plumb this directly into your engine!

Screenshots

Screenshot 1

Screenshot 2

Screenshot 3

Screenshot 4

Similar projects and links

Here are links to some awesome similar and related projects:

Owner
Xi Ma Chen
Coder. Pen spinner. Rendering engineer at Sledgehammer Games. Worked on Nintendo Switch. Worked on Call of Duty: WWII. Hobby game designer and composer.
Xi Ma Chen
A scripting language created mainly for game engines

HCode Hammurabi's Code A scripting language created for the use in games and game engines. Currently supported features and roadmap Structs Functions

null 4 Oct 11, 2020
Animation compression is a fundamental aspect of modern video game engines

Animation compression is a fundamental aspect of modern video game engines. Not only is it important to keep the memory footprint down but it is also critical to keep the animation clip sampling performance fast.

Nicholas Frechette 972 Aug 7, 2022
Insomniac games cache simulation tool plugin for UE4

Insomniac Games CacheSim plugin for UE4 This plugin for Unreal Engine 4 lets you use the Insomniac Games Cache Simulation tool to detect cache misses

Toni Rebollo Berná 28 Jul 25, 2022
To recreate the board game Scotland yard and enable a single player to play the game by letting one of the roles being played by the computer based on written algorithm

Scotland Yard GAME OF SCOTLAND YARD This is a custom version of the classic board game, Scotland Yard .The game uses the London map used in the origin

Brshank 2 Nov 11, 2021
C++ game engine inspired by quake. Modern rendering and quake mapping tool integration.

Nuake Feel free to join the discord server for updates: What is it Nuake is a game engine written from scratch by myself. It is not meant to be a end-

Antoine Pilote 23 Jul 23, 2022
High Performance 3D Game Engine, with a high emphasis on Rendering

Electro High Performance 3D Game Engine, with a high emphasis on Rendering MainFeatures Rendering PBR Renderer (Cook–Torrance GGX) IBL (Image Based Li

Surge 44 Jul 28, 2022
A Minecraft like game with basic rendering, movement, block placement.. All made from scratch

Voxel-Game-Demo A Minecraft like game with basic rendering, movement, block placement.. All made from scratch Downlod Pre-compiled binaries (executabl

null 1 Dec 30, 2021
Intrinsic is a Vulkan based cross-platform game and rendering engine

Intrinsic is a Vulkan based cross-platform game and rendering engine

Benjamin Wrensch 1k Jul 31, 2022
A single-header C++ library for making simple 2D games

A single-header C++ library for making simple 2D games PLATFORM: Windows LANGUAGE: C++ ENVIRONMENT: Visual Studio Why? Learning C++ is often seen as d

Sumo Digital Academy 45 Aug 5, 2022
Improved version of the X-Ray Engine, the game engine used in the world-famous S.T.A.L.K.E.R. game series by GSC Game World.

OpenXRay OpenXRay is an improved version of the X-Ray Engine, the game engine used in the world-famous S.T.A.L.K.E.R. game series by GSC Game World. S

null 2k Aug 10, 2022
Stealthy way to hijack the existing game process handle within the game launcher (currently supports Steam and Battle.net). Achieve external game process read/write with minimum footprint.

Launcher Abuser Stealthy way to hijack the existing game process handle within the game launcher (currently supports Steam and Battle.net). Achieve ex

Ricardo Nacif 76 Jul 28, 2022
Game Boy, Game Boy Color, and Game Boy Advanced Emulator

SkyEmu SkyEmu is low level cycle accurate GameBoy, GameBoy Color and Game Boy Advance emulator that I have been developing in my spare time. Its prima

Sky 193 Aug 6, 2022
noclip is a single-header backend for a developer console

noclip Many computer games have a developer console or in-game console which provide a command-line interface for executing commands, changing game va

Kevin Chin 8 Mar 20, 2022
Magarena is a single-player fantasy card game played against a computer opponent.

Magarena is a single-player fantasy card game played against a computer opponent.

MagArena 351 Jul 20, 2022
sdl4cpp, header-only C++ wrapper around SDL2.

sdl4cpp sdl4cpp, header-only C++ wrapper around SDL2 (heavily work-in-progress) An example: #include "sdl4cpp/sdl4.hpp" #include "sdl4cpp/timer.hpp" #

Ferhat Geçdoğan 1 Nov 28, 2021
Creating Unreal Engine infinite landscapes/oceans using the editor shader graph and rendering them using Geometry ClipMap. It also allows to spawn mesh on landscape surface. UE5 required

Procedural Landscapes and Oceans in Unreal Engine 5 using Editor Shader Graph Latest version of this project is available as a plugin for UE 4.26+ on

Maxime Dupart 10 Oct 4, 2021
Exploring the modern rendering landscape

HellTech Engine An WIP exploration of the modern rendering landscape with Vulkan 1.2+ on Windows. REQUIREMENTS: Win10+ Vulkan1.2+ dedicated GPU ( ?, p

null 7 Jul 11, 2022
Code samples to show how to use Rendering features in Unreal :)

UE4GraphicsSample Code samples to show how to use Rendering features in Unreal :) Clear Texture Example (MAP_ClearTexture) Shows basics of how to use

Amit Kumar Mehar 51 Jul 29, 2022
VTK is an open-source software system for image processing, 3D graphics, volume rendering and visualization

Introduction VTK is an open-source software system for image processing, 3D graphics, volume rendering and visualization. VTK includes many advanced a

Kitware, Inc. 1.9k Aug 5, 2022