2017-11-20
PNG Textures in Trenchbroom
Coal's levels are technically Quake 3 IBSP files (version 46), but they're first made with Trenchbroom, a fairly new and modern Quake editor. I like it for its simple 3D editing view, its "lightness" (uncompressed, it's ~40 MB compared to GTKRadiant's 311MB) and the fact that it is Free Software ™ and has binaries for Windows and GNU/Linux. It's served me well in all the time I've used it. Except for texturing.
While Trenchbroom is originally a Quake editor, Coal loads textures much like Quake 3 does - either from loose files in its base directory or from zipped "pak" files. By default, Trenchbroom expects you to supply a Quake "WAD" file that contains textures, and this had presented multiple problems for me.
- Most software for editing/creating WAD files are Windows only.
- The editing software I used (TexMex) doesn't load PNGs. I'm forced to batch convert my textures to either TGA or JPG, add them to the WAD, then delete the converted files.
- Because I have multiple directories of textures (to simplify attribution to different sources), I need to modify filenames of textures in the WAD to include the directory they're in.
- WAD textures have a filename character limit of sixteen. Quake 3 BSP textures have a limit of 64, so this feels unfairly limiting! You sometimes have to get creative with renaming filenames to fit, especially when they come from other sources. Truncating filenames also makes it harder to find the original file if I ever need to.
- TexMex can change the colors of WAD textures to fit Quake's palette, making them appear differently in Trenchbroom than in the final game.
I've tolerated this limitation for almost a year, until I learned that Trenchbroom had been able to load PNGs for some time now, though only if built from source in its git master branch.
In Trenchbroom, you can make a unique configuration for your game that allows you to specify how it should load textures. By default, Quake loads "idmip" textures from WAD files, while Quake 2 loads "idwal" textures from a directory. According to Trenchbroom's source, I just need to specify my texture format as "image" and the extension as "png".
Since the latest release of TB (RC4) doesn't do this, I was forced to enter the wonderful world of compiling open source software on Windows.
Compiling wxWidgets was simple enough, though it did make me appreciate that I don't work on GUI code (the final size of the directory was 1GB). Even though Trenchbroom's git repo includes compiled library files for FreeImage and FreeType, they were incompatible with my version of MinGW 64 (gcc version 5.10) and I was forced to build them as well.
FreeType was pleasant to build (16 seconds to build libfreetype.dll from CMake). FreeImage was a nightmare - besides taking over 4 minutes to compile (I just want images to show in a level editor!), it required me to fix or stub out problematic lines of code in a few of it's sub libraries that Trenchbroom probably doesn't use, as well as remove an include directory in it's makefile that was causing a compile error in MinGW's own headers. It's made me realize how valuable something like Sean Barrett's public domain libraries are. In the future, I might use stb_image as a drop-in replacement to FreeImage.
In the end, I got what I wanted.
Until Trenchbroom gets an official release with generic image support, I'll be using this custom build going forward.