These script files will generate TGA/PNG bitmap font textures and FNT/DAT data files for Return to Castle Wolfenstein (RTCW) and RealRTCW from TrueType fonts (TTF/TTC).
Prerequisites
Python 3.12 or later recommended.
Required libraries and recommended version:
- numpy: 1.26.4
- pillow: 12.0.0
- fonttools: 4.60.1
Quick Start
- Clone or download the scource files.
- Install dependencies libraries.
pip install -r requirements.txt- Place your TrueType font files (.ttf or .ttc) in a directory (e.g., ./ttffont/)
- Modify the main.py file to configure your font generation by editing some parameters in main.py
- Execute the main script:
python main.py
By default, the script will:
- Generate TGA font textures and a base FNT file.
- Convert the FNT file to a DAT file (RTCW binary format)
Custom Configuration
You can generate fonts from multiple TTF files, just adjust corresponding_table, syntax:
# example
corresponding_table = [
[
filepath,
[(index begin, index end), ...],
fontsize # Optional parameters, if not set, will use default_font_size
],
...
]You can adjust generation parameters in the generate() method:
generator.generate(
output_name=output_name,
texture_width=1024, # Texture atlas width
texture_height=1024, # Texture atlas height
char_margin=2, # Margin around each character
char_spacing=2, # Spacing between characters
texture_margin=8, # Margin around texture edges
max_workers=8, # Number of cpu cores for parallel processing
texture_format="tga" # "tga" or "png" format
)File Formats Generated
- Texture files: .tga or .png files containing font glyphs.
- FNT file: Text-based font data file for reading or editing.
- DAT file: Binary font data file for RTCW/RealRTCW game engine.
Advanced Setting
- Unicode Support: Set max_glyphs=65536 for extended Unicode support (default: 256 for RTCW)
- Developer Mode: Enable developer_mode=True to draw debugging borders
Notes
- The tool will first look for fonts in the specified path, then try the Windows system fonts directory if not found.
- RTCW's default font limit is 256 glyphs. Modify both the script and RTCW code for more glyphs.
- The font_size parameter doesn't exactly match RTCW's font size system.
- Supported font formats: TrueType (.ttf) and TrueType Collections (.ttc)
- If you get font loading errors, ensure the font path is correct.
- For Unicode support, verify your font contains the required characters.