- Joined
- Aug 1, 2023
- Messages
- 76
Texttags (also known as floating text) are those texts that appear in the 3d game world like "42!" (after a critical strike) or "miss" (after a missed attack), or hovering over a hero to read their name and level, or created from script using the CreateTextTag function. These texts have a 3d world position and they appear to always be facing the camera. I was curious how the game renders them, and at first I thought that the game draws the text into a texture/bitmap and then creates a single camera facing quad with it, or for each character in the text, it created a separate camera facing quad. After experimenting a bit I noticed that texttags have the same size regardless of how far the camera is from them, so I thought that they could be using an orthographic projection. It turns out it was much simpler than that. Their position is simply transformed from world space to screen space and then they are rendered like a text would be rendered by BJDebugMsg.
In some high level hand-wavy code it could look like:
We basically reduce the problem of rendering texttags, to that of rendering text on the screen, which unfortunately is a big rabbit hole of its own. Here are some pointers 1, 2, 3, 4, 5, 6, 7 though.
Its funny, Warcraft 3 seems pretty complicated (to me at least), a 3d multiplayer rts game, with single player campaign, save/loading, replays, modding support, custom scripting language, custom ui framework, custom model and texture formats, custom archive format, with many gameplay mechanics interacting in interesting ways, and yet it draws the line on text/font rendering by using a library (FreeType).
In some high level hand-wavy code it could look like:
JASS:
mat4 screen_from_world = ...
vec3 world_texttag_pos = GetTextTagPos(our_texttag)
vec4 screen_texttag_pos = screen_from_world * vec4(world_texttag_pos, 1.0)
vec2 screen_pos = vec2(screen_texttag_pos.x, screen_texttag_pos.y) * (1.0 / screen_texttag_pos.w) // perspective divide
ScreenDrawText(screen_pos, GetTextTagText(our_texttag))
We basically reduce the problem of rendering texttags, to that of rendering text on the screen, which unfortunately is a big rabbit hole of its own. Here are some pointers 1, 2, 3, 4, 5, 6, 7 though.
Its funny, Warcraft 3 seems pretty complicated (to me at least), a 3d multiplayer rts game, with single player campaign, save/loading, replays, modding support, custom scripting language, custom ui framework, custom model and texture formats, custom archive format, with many gameplay mechanics interacting in interesting ways, and yet it draws the line on text/font rendering by using a library (FreeType).







