【发布时间】:2019-12-04 04:56:48
【问题描述】:
我想在字符串中输入 '\n' 来换行并渲染文本。
目前,如果我尝试在 '\n' 输入后换行,渲染输出看起来像这样。
我希望第二行与第一行对齐。
这是代码
// Iterate through all characters
std::string::const_iterator c;
for (c = text.begin(); c != text.end(); c++)
{
Character ch = Characters[*c];
GLfloat xpos = x + ch.Bearing.x * scale;
GLfloat ypos = y - (ch.Size.y - ch.Bearing.y) * scale;
// i check the input here
// if( *ch == '\n')
// Reset the Xpos value in the freetype.
GLfloat w = ch.Size.x * scale;
GLfloat h = ch.Size.y * scale;
// Update VBO for each character
GLfloat vertices[6][4] = {
{ xpos, ypos + h, 0.0, 0.0 },
{ xpos, ypos, 0.0, 1.0 },
{ xpos + w, ypos, 1.0, 1.0 },
{ xpos, ypos + h, 0.0, 0.0 },
{ xpos + w, ypos, 1.0, 1.0 },
{ xpos + w, ypos + h, 1.0, 0.0 }
};
// Render glyph texture over quad
glBindTexture(GL_TEXTURE_2D, ch.textureID);
// Update content of VBO memory
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// Render quad
glDrawArrays(GL_TRIANGLES, 0, 6);
x += (ch.Advance >> 6) * scale;
}
虽然我已经能够通过将浮点变量增加给定值并将变量减去 xpos 来实现这一点。我觉得这是一种解决方法
freetype 中是否有任何功能可以将字体的 Xpos 重置为起始位置。
【问题讨论】:
-
“我们在 freetype 中是否有任何功能可以将字体的 Xpos 重置为起始位置。” - 字体没有起始位置。字形位置
x由您的代码控制(freetype 不知道您是如何做到的)。开头的x是什么?重置x,定义一个换行符(y = y + linefeed)和continue循环。
标签: opengl glsl freetype freetype2