2014-04-09 308 views
1

我正在使用FreeType2 for fornt呈現。我的問題是字體大小。我在左上角有原點[0,0],字體大小設置爲屏幕的全高。我的渲染結果可以在圖片中看到。FreeType2 - 字體大小較小

enter image description here

爲什麼字體不充盈我窗口的整個高度?

我的渲​​染代碼:

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; 

    } 

回答

5

您需要更完整的文本來理解問題進行測試。字形由內部領先,上升,下降組成。你想要的計算似乎是Ascent。此外,你必須問自己,如果你想支持像「Á」或小寫「P」的文本。

Font Metrics

+0

愚蠢的。我已經完全忘了領先的字體的一部分。謝謝 –