Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何将freetypegl与{0,w,h,0}正交投影一起使用?_C++_Opengl_Text_Projection_Freetype - Fatal编程技术网

C++ 如何将freetypegl与{0,w,h,0}正交投影一起使用?

C++ 如何将freetypegl与{0,w,h,0}正交投影一起使用?,c++,opengl,text,projection,freetype,C++,Opengl,Text,Projection,Freetype,freetypegl是为使用{0,w,0,h)投影而编写的,这个库中包含的几乎所有演示都使用该投影。我更喜欢{0,w,h,0},我不知道如何更改代码以使用该正交。我尝试反转UV,但随后文本与上限对齐,看起来不太好 如何更改代码以使用{0,w,h,0}投影? void AddGlyph(Vector2& position, const char c, uint color, texture_font_t* ftFont) { texture_glyph_t* glyph = tex

freetypegl是为使用{0,w,0,h)投影而编写的,这个库中包含的几乎所有演示都使用该投影。我更喜欢{0,w,h,0},我不知道如何更改代码以使用该正交。我尝试反转UV,但随后文本与上限对齐,看起来不太好

如何更改代码以使用{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);
    } 
}
void AddGlyph(矢量2和位置、常量字符c、单位颜色、纹理字体*ftFont)
{
纹理字形=纹理字体字形(ftFont,&c);
如果(c){
如果(字符串){
位置.x+=纹理\字形\获取\紧排(字形,&c-1)*比例;
}
//一个标志符号是四边形,四边形有4个顶点和6个元素,
//这对案件没有影响
MapBuffer(4,6);
浮动x0=位置x+静态施法(字形->偏移x),
y0=位置y+静态施法(字形->偏移y),
x1=x0+静态施法(字形->宽度),
y1=y0-静态施法(字形->高度),
u0=字形->s0,
v0=字形->t0,
u1=字形->s1,
v1=字形->t1;
//顶点结构是位置、uv、颜色
AddVertexData(向量2(x0,y0),向量2(u0,v0),颜色);
AddVertexData(矢量2(x0,y1),矢量2(u0,v1),颜色);
AddVertexData(矢量2(x1,y1),矢量2(u1,v1),颜色);
AddVertexData(向量2(x1,y0),向量2(u1,v0),颜色);
//默认矩形元素依赖关系
AddRectElements();
位置x+=字形->前进x*比例;
}
}
无效字符串(常量标准::字符串和文本、矢量2和位置、uint颜色、常量字体和字体)
{
使用名称空间ftgl;
纹理_font_t*ftFont=font.getFTFont();
用于(常量自动和c:文本){
AddGlyph(位置、c、颜色、字体);
} 
}

也许我应该更改库代码?如果是,我应该更改什么?

我尝试反转UV您是如何尝试反转UV的?嗯,将行
v0=glyph->t0
v1=glyph->t1
更改为
v0=glyph->t1
v1=glyph->t0
就足够了,因为这将导致垂直镜像的te纹理映射。或者这是你尝试过的,但它不起作用吗?是的,这是我尝试过的。可能是,矩形正好反映了轮廓线覆盖的区域。因此,镜像v意味着轮廓线的基线不再匹配。因此,你必须分别更改y。如果你保持UV不变,但更改
y1=y0-静态投影(轮廓线->高度),会怎么样,
y1=y0+static\u cast(glyph->height),
?请注意,这会改变四边形的方向。因此,您可能必须调整面剔除。可能是,最好禁用它,直到您正确操作为止。不,它看起来与UV更改后略有不同,但仍然不正确。是的!`y0=position.y-static\u cast(glyph->offset_y)+(ftFont->ascender+ftFont->depender)`行得通!我想知道什么是上升和下降,我不太明白。我找到了维基百科的公式,但对我来说有点不清楚。