freetypegl被编写为与{0,w,0,h)投影一起使用,几乎所有包含在该库中的演示都与该投影一起工作。我更喜欢{0,w,h,0},但我不知道如何更改代码以能够与该邻位一起使用。我试图反转uvs,但随后文本与上限对齐,看起来不太好。
如何更改代码以适用于{0,w,h,0}投影?
void AddGlyph(Vector2& position, const char c, uint color, texture_font_t* ftFont)
{
texture_glyph_t* glyph = texture_font_get_glyph(ftFont, &c);
if (c) {
if (string) {
position.x += texture_glyph_get_kerning(glyph, &c- 1) * scale;
}
//One glyph is a quad and quad has 4 vertices and 6 elements,
//it does not impact the case
MapBuffer(4, 6);
float x0 = position.x + static_cast<float>(glyph->offset_x),
y0 = position.y + static_cast<float>(glyph->offset_y),
x1 = x0 + static_cast<float>(glyph->width),
y1 = y0 - static_cast<float>(glyph->height),
u0 = glyph->s0,
v0 = glyph->t0,
u1 = glyph->s1,
v1 = glyph->t1;
//vertex struct is position, uv, color
AddVertexData(Vector2(x0, y0), Vector2(u0, v0), color);
AddVertexData(Vector2(x0, y1), Vector2(u0, v1), color);
AddVertexData(Vector2(x1, y1), Vector2(u1, v1), color);
AddVertexData(Vector2(x1, y0), Vector2(u1, v0), color);
//default rectangle elements dependence
AddRectElements();
position.x += glyph->advance_x * scale;
}
}
void DrawString(const std::string& text, Vector2& position, uint color, const Font& font)
{
using namespace ftgl;
texture_font_t* ftFont = font.getFTFont();
for (const auto& c : text) {
AddGlyph(position, c, color, ftFont);
}
}
也许我应该更改库代码?如果是这样,我应该怎么改变?