gpt4 book ai didi

c++ - glVertex3f 缩放问题

转载 作者:行者123 更新时间:2023-11-28 02:15:05 24 4
gpt4 key购买 nike

OpenGL 的新手,请放轻松。我的任务是使用 GLFont 在我的学校项目中呈现文本,我在下面粘贴了它的呈现方法。我使用 glOrtho 将原点设置为窗口的左上角,但这会导致 GLFont 渲染字符上下颠倒的问题。我需要做的是按 -1 缩放 y 我相信,但我不知道如何更改下面的渲染器来做到这一点。有什么想法吗?

void GLFont::RenderText (const char* String, float x, float y, float z, float size)
{
//Return if we don't have a valid glFont
if (!ok)
{
throw GLFontError::InvalidFont();
}

//Get length of string
int Length = strlen(String);

//Begin rendering quads
glBegin(GL_TRIANGLE_STRIP);

//Loop through characters
for (int i = 0; i < Length; i++)
{
//Get pointer to glFont character
GLFONTCHAR *Char = &Font.Char[(int)String[i] - Font.IntStart];

float dx = Char->dx*size;
float dy = Char->dy*size;

//Specify vertices and texture coordinates
glTexCoord2f(Char->tx1, Char->ty2);
glVertex3f(x, y - dy, z);
glTexCoord2f(Char->tx1, Char->ty1);
glVertex3f(x, y, z);
glTexCoord2f(Char->tx2, Char->ty2);
glVertex3f(x + dx, y - dy, z);
glTexCoord2f(Char->tx2, Char->ty1);
glVertex3f(x + dx, y, z);

//Move to next character
x += dx;
}

//Stop rendering quads
glEnd();
}

最佳答案

我建议在您的代码中反转“char->ty1”和“char->ty2”,而不是缩放:

//Specify vertices and texture coordinates
glTexCoord2f(Char->tx1, Char->ty1);
glVertex3f(x, y - dy, z);
glTexCoord2f(Char->tx1, Char->ty2);
glVertex3f(x, y, z);
glTexCoord2f(Char->tx2, Char->ty1);
glVertex3f(x + dx, y - dy, z);
glTexCoord2f(Char->tx2, Char->ty2);
glVertex3f(x + dx, y, z);

这将导致通过 y 轴的反向纹理映射。

希望对您有所帮助!

关于c++ - glVertex3f 缩放问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34248886/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com