I am using some Chinese fonts and it seems the bitmap fonts generated by the FreeTypeFontGenerator
will have missing characters with certain FreeTypeFontParameter
settings . I will show some examples below.
IMG01 [test_font.ttf, font size 16, border width 2] Looks good.
IMG02 [test_font.ttf, font size 24, border width 3] Characters missing.
IMG03 [microsoft_yahei_bold.ttf, font size 24, border width 3] Switched to a more promising Microsoft font and the situation seems to become worse.
Core codes for IMG02:
public class GameContext extends ApplicationAdapter {
private BitmapFont font;
private SpriteBatch batch;
@Override
public void create() {
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("test_font.ttf"));
String characters = Gdx.files.internal("characters.txt").readString("UTF8");
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = 24;
parameter.color = Color.WHITE;
parameter.borderColor = Color.BLACK;
parameter.borderWidth = 3;
parameter.characters = FreeTypeFontGenerator.DEFAULT_CHARS + characters;
font = generator.generateFont(parameter);
batch = new SpriteBatch();
}
@Override
public void render() {
Gdx.gl.glClearColor(0.9f, 0.9f, 0.9f, 1.0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
font.draw(batch, "This is a test string zzz...", 10, Gdx.graphics.getHeight() / 2);
batch.end();
}
@Override
public void dispose() {
font.dispose();
}
}
Note: The characters.txt
file includes some Chinese characters and punctuation which I need to use in my game.
You can find the example project here.
1.9.3
Only tested on android and windows.
Please add the following line to check whether that makes any difference:
FreeTypeFontGenerator.setMaxTextureSize(2048);
Please add the following line to check whether that makes any difference:
FreeTypeFontGenerator.setMaxTextureSize(2048);
It actually works! Thank you so much!
Duplicate of #3525
Most helpful comment
Please add the following line to check whether that makes any difference: