Cinder 中文显示二三事

来源:互联网 发布:德意志意识形态 知乎 编辑:程序博客网 时间:2024/05/22 17:49
1. 字符串转换

首先要把 wstring 转换成 utf8-string(cinder在之后又会把utf8转换成utf16)

wstring s = L"是大地的泪点,使她的微笑保持着青春不谢。\nIt is the tears of the earth that keep here smiles in bloom.";
string utf8str = toUtf8(s);

2. 加载字体

//mfont = Font(loadAsset("FZSTK.TTF"), 32);
mfont=Font("STXINGKA",32);      // 系统字体用字体文件名

3. 获取字体的shape2d

//Font::Glyph gly = mfont.getGlyphChar(utf8str[0]);      // 这种方式不行,wide-utf8之后占了好几位
vector<Font::Glyph>glyphs = mfont.getGlyphs(utf8str);      // 所以还是得使用这种方式,获取所有

shape2d s2d = mfont.getGlyphShape(glyphs[0]);

4. 用 TexBox 显示

TextBox tb = TextBox().font(mfont).text(utf8str);
gl::Texture tex = gl::Texture( tb.render() );
原创粉丝点击