.FNT -- Bitmap Font Typography

1. Architectural Role & Engine Purpose

The FNT (Font File) format stores font glyph metrics, character kerning data, and raster atlases in Project I.G.I. 1.

FNT files provide the typography for tactical on-screen displays, mission objectives, computer terminal hacking interfaces, ammo counts, and subtitles. The format maps ASCII characters (0–255) to precise pixel coordinates within a packed texture atlas.

2. Binary File Layout & Memory Map Diagram

An FNT file contains a font descriptor header, a 256-entry glyph metrics table, and the raw font atlas bitmask:

FNT FONT — GLYPH METRICS & RASTER ATLAS LAYOUT 0x00: Font Descriptor Header (16 Bytes) 16 BYTES Font Height, Baseline | First Char (32), Last Char (255) | Atlas Width, Height | Flags font_height, baseline, first_char, last_char, atlas_w, atlas_h, flags 256-Entry Glyph Metric Table (256 * 16 Bytes) GLYPH METRICS Per-character typography bounds: Width, Height, XAdvance, Bearing X/Y, Atlas UV Rect (U0, V0, U1, V1) O(1) Direct ASCII indexing • Precomputed texel coordinates Font Raster Texture Atlas Buffer TEXTURE ATLAS Atlas Width * Atlas Height Bytes: 1-bit monochrome bitmask or 8-bit alpha coverage atlas Monospaced and proportional tactical military typefaces

3. Text Rendering & Quad Emission Pipeline Diagram

When DrawString("OBJECTIVE COMPLETE") is called, the font renderer transforms characters into Direct3D quads:

FNT FONT — TEXT RASTERIZATION & SCREEN QUAD PIPELINE 1. DRAWSTRING CALL • DrawString("TARGET", X, Y) • Iterate ASCII Chars • Init Screen Cursor X 2. GLYPH LOOKUP • Metric = pGlyphs[Char] • Read UV Texel Rect • Read XAdvance Step 3. QUAD BATCHING • Emit 2 Triangles per Char • Dynamic Screen VBO • Batch Entire Sentence 4. D3D7 DRAW • Bind Atlas Texture • DrawPrimitive Quad • Single Draw Call UI

4. Architectural Mechanics & Engine Implementation Details

The FNT format was designed for minimal batching overhead:

  • Single-Pass Batching: Entire sentences or HUD dialogue blocks are transformed into a single dynamic vertex buffer containing all character quads, rendering the entire UI in a single Direct3D draw call.
  • Fixed-Width Fast Path: Monospaced military fonts (used for terminal hacking and coordinate readouts) bypass kerning calculations entirely, executing at peak frame rates.

5. C++ Struct Definitions

#pragma pack(push, 1)
struct FntHeader {
    uint16_t font_height;   // Line height in pixels
    uint16_t baseline;      // Distance from top to text baseline
    uint16_t first_char;    // Typically 32 (Space)
    uint16_t last_char;     // Typically 255
    uint16_t atlas_width;   // Width of font texture atlas
    uint16_t atlas_height;  // Height of font texture atlas
    uint32_t flags;         // 0=1-bit, 1=8-bit alpha
};

struct FntGlyphMetric {
    uint16_t width;         // Glyph pixel width
    uint16_t height;        // Glyph pixel height
    int16_t  x_advance;     // Horizontal cursor step
    int16_t  bearing_x;     // Left side offset
    int16_t  bearing_y;     // Top offset relative to baseline
    uint16_t u0, v0;        // Top-left atlas texel coordinates
    uint16_t u1, v1;        // Bottom-right atlas texel coordinates
};
static_assert(sizeof(FntHeader) == 16, "FntHeader must be 16 bytes");
#pragma pack(pop)