如何在 Direct3D 11 上使用字體文件渲染文本? (How can I render text using font files on Direct3D 11?)


問題描述

如何在 Direct3D 11 上使用字體文件渲染文本? (How can I render text using font files on Direct3D 11?)

我已經閱讀了很多關於此的問題,但它們並不能滿足我想要做的事情。我正在嘗試在我的應用程序中使用 TTF 文件作為文本字體,我想使用 Direct Draw,但是 tutorial 來自 Microsoft 網站,僅說明瞭如何將其與 Direct2D 一起使用。我應該如何從這個文件加載數據並使用這個文件的字體為我的 Direct3D 應用程序渲染文本?我還閱讀了有關 AddFontResourceExA() 函數的信息,但我沒有找到任何關於如何使用它的內容。我真的迷路了,因此感謝您的幫助。


參考解法

方法 1:

There are basically two approaches for rendering text on a Direct3D 11 Render Target / Texture.

  1. Rendering using a 'sprite sheet'. Here you capture the font at a particular resolution and generate a texture from it. Then you use the texture to render the glyphs as textured triangles. This is very fast and inexpensive to render, but does not scale to arbitrary resolutions (you can capture the 'sprite sheet' at multiple point sizes to get some scaling) and does not work well with "CKJ" languages due to the large size of the fonts. For an example of this, see SpriteFont in the DirectX Tool Kit. This is what legacy D3DX9/D3DX10 did as well.

  2. Rendering using vector fonts directly. Here you have some kind of library that generates triangles 'on‑the‑fly' from the "TrueType" vector font data. This is what Direct2D+DirectWrite is designed to do. You can use interop with Direct3D 11 surfaces, but essentially you are using DirectWrite ‑> Direct2D ‑> shared texture. Then you draw the shared texture with Direct3D as a 'sprite'. This is more complicated to setup, but results in arbitrary resolutions scaling, support for large character set fonts, and handles complex writing systems.

(by Rafael FerreiraChuck Walbourn)

參考文件

  1. How can I render text using font files on Direct3D 11? (CC BY‑SA 2.5/3.0/4.0)

#direct3d11






相關問題

Адлюстраванне дынамічнага буфера ў Direct3D11 у праграме Windows Store (Mapping a dynamic buffer in Direct3D11 in a Windows Store App)

未處理的異常@ClearRenderTargetView() (Unhandled exception @ ClearRenderTargetView())

將 3d 模型導入 Direct3D 11 示例 (Importing 3d model to Direct3D 11 Example)

編譯器不允許我使用“DDSTextureLoader.h”和“WICTextureLoader.h” (Compiler won't let me use "DDSTextureLoader.h" and "WICTextureLoader.h")

在我從舊版 DirectX SDK 更改為 Windows SDK (Visual Studio 2015) 後,鏈接器一直在抱怨 (The linker keeps complaining after I changed from legacy DirectX SDK to Windows SDK (Visual Studio 2015)))

鏈接器給出了我在我的應用程序中根本沒有使用過的函數的錯誤 (Linker gives errors about a function that i have not used in my application at all)

Direct3D 11 中輸出圖像的雙線性過濾 (Bilinear filtering of output image in Direct3D 11)

Direct3D 編程新手:11 與 12 (New to Direct3D programming: 11 vs 12)

如何在 Direct3D 11 上使用字體文件渲染文本? (How can I render text using font files on Direct3D 11?)

獲取 D3D 調試信息? (Get D3D debug information?)

為什麼 XMMatrixLookAtLH 會導致調試錯誤? (Why does XMMatrixLookAtLH result in a debug error?)

InterlockedAdd HLSL 潛在優化 (InterlockedAdd HLSL potential optimization)







留言討論