Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't load prerendered font correctly #332

Open
karriszou opened this issue Aug 12, 2022 · 1 comment
Open

Can't load prerendered font correctly #332

karriszou opened this issue Aug 12, 2022 · 1 comment

Comments

@karriszou
Copy link

char shaderName[32];

Because max size of shaderName in glyphInfo_t is 32 bytes, cause when load font such as fonts/LiberationMono-Regular_0_8 the shaderName is truncated as fonts/LiberationMono-Regular_0_ so that shader of glyph not be registered correctly.

By the way, @zturtleman I know spearmint because your replay in ioquake3 forum about truetype font render, I know your work is really great! but, I'd really like to know:

How spearmint render CJK fonts? I know this is a bit tricky, firstly to accommodate a large number of Chinese glyphs, the glyph array will become very big, but for latin fonts this is obviously a waste of memory space, and secondly the prerendered font texture will also be large, but there are some ways to improve, such as the post:font-chaos, or collect the codepoints for all Chinese characters used by the game, and then load only the glyph for used, aka initialize the font from specific codepoints instead of a codepoint range.

What is your opinion? Will spearmint support rendering CJK in the future? it would be great if so!

Thanks in advance!

@zturtleman
Copy link
Owner

Spearmint development is on hiatus for years while I work on a new private game engine. I don't have any plans to work on Spearmint font support soon.

The 32 character shader name limit is an unfortunate hang over from Quake III: Team Arena. I didn't really test new fonts using pre-rendered .dat. The .dat files created by Spearmint still work with Team Arena but it would be possible to extend shader name by adding a new alternate format. Could save space by the fontInfo having a list of shader names (MAX_QPATH char limit) and glyphInfo just have an index into the shader name list.

My pipe dream for supporting drawing all font glyphs is to draw the vector outlines directly, without rendering it to a texture. (I don't actually know how to do this but it needs GLSL shader so it's not compatible with OpenGL 1 used by Spearmint's default renderer.)

My more realistic idea for supporting drawing all font glyphs is to dynamically update a texture instead of pre-uploading all supported font glyphs. (Cache glyph bitmaps generated by Freetype and manage a texture atlas that is uploaded to OpenGL.) This needs a new CGame API to get per-frame dynamic font shader / texcoords (glyphInfo_t basically) or (preferably) APIs to draw a string and get a string's width, height, whatever.

I dislike the idea of limiting CGame to whatever the draw string API provides however due to ligatures (also used by emoji, which I am particularly interested in) CGame can't assume one Unicode code point equals one glyph. So the new CGame API should probably deal with strings instead of getting glyph info for individual code points. Though converting UTF-8 string to font-specific glyph indexes to work with might be an option.

Spearmint's TrueType font support is one of those things where it works well but it seems like the whole thing needs to be overhauled to do the other things I want it to do. Adding additional pre-loaded characters to fontInfo is definitely an easier route.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants