繁体   English   中英

FreeType2-字体较小

[英]FreeType2 - font size is smaller

我正在使用FreeType2进行fornt渲染。 我的问题是字体大小。 我的原点[0,0]位于左上角,字体大小设置为屏幕的全高。 我的渲染结果可以在图片上看到。

在此处输入图片说明

为什么字体不能填充整个窗口高度?

我的渲染代码:

int devW, devH;
    device->GetViewport(&devW, &devH);

    float sx = 2.0f / static_cast<float>(devW);
    float sy = 2.0f / static_cast<float>(devH);

    x = MyMath::MyMathUtils::MapRange(0, 1, -1, 1, x);
    y = MyMath::MyMathUtils::MapRange(0, 1, -1, 1, y);


    MyStringWide wText = MyStringWide(text);
    this->fontQuad->PrepareForRender();
    for (int i = 0; i < wText.GetLength(); i++)
    {
        int znak = wText[i];

        unsigned long c = FT_Get_Char_Index(this->fontFace, znak);
        FT_Error error = FT_Load_Glyph(this->fontFace, c, FT_LOAD_RENDER);


        FT_GlyphSlot glyph = this->fontFace->glyph;

        MyStringAnsi textureName = "Font_Renderer_Texture";
        textureName += "_";
        textureName += znak;

        if (GetTexturePoolInstance()->ExistTexture(textureName) == false)
        {
            GetTexturePoolInstance()->AddTexture2D(textureName, 
                glyph->bitmap.buffer, glyph->bitmap.width * glyph->bitmap.rows, 
                MyGraphics::A8, 
                glyph->bitmap.width, glyph->bitmap.rows, 
                false,
                true);
        }



        float x2 = x + glyph->bitmap_left * sx;
        float y2 = -y - glyph->bitmap_top * sy;
        float w = glyph->bitmap.width * sx;
        float h = glyph->bitmap.rows * sy;


        this->fontQuad->GetEffect()->SetVector4("cornersData", MyMath::Vector4(x2, y2, w, h));
        this->fontQuad->GetEffect()->SetVector4("fontColor", fontColor);
        this->fontQuad->GetEffect()->SetVector4("texCoordData", MyMath::Vector4(0, 0, 1, 1));       
        this->fontQuad->GetEffect()->SetTexture("fontTexture", textureName);

        this->fontQuad->RenderEffect("classic", 0, this->fontQuad->GetNumVertices(), 0, this->fontQuad->GetNumPrimitives());

        x += (glyph->advance.x >> 6) * sx;
        y += (glyph->advance.y >> 6) * sy;

    }

您需要使用更完整的文本进行测试才能理解问题。 字形由内部前导,上升,下降组成。 您想要进行计算的似乎是Ascent。 另外,您必须问自己是否要支持“Á”或小写“ p”之类的文本。

字体指标

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM