将指定的字体与directx-11一起使用
Use specified font with directx-11
我想使用DirectX 11 的指定字体文件
搜索后,我被困在创建一个自定义字体集合。
加载指定字体文件的代码:
Platform::String^ pathTEST;
Microsoft::WRL::ComPtr<IDWriteFontFile> fontFileTEST;
Microsoft::WRL::ComPtr<IDWriteFontFileLoader> fontFileLoaderTEST;
Windows::Storage::StorageFolder^ folder = Windows::Storage::ApplicationData::Current->LocalFolder;
pathTEST = folder->Path + L"\Bubblegum.ttf";//#BubbleGum
HRESULT hr = S_OK;
if (SUCCEEDED(hr))
hr = dwriteFactory->CreateFontFileReference(pathTEST->Data(), NULL, &fontFileTEST);
if (SUCCEEDED(hr))
hr = fontFileTEST->GetLoader(&fontFileLoaderTEST);
if (SUCCEEDED(hr))
hr = dwriteFactory->RegisterFontFileLoader(fontFileLoaderTEST.Get());
应该使用字体的代码,但我缺少字体集合:
MyIDWriteFactory2->CreateTextFormat(
L"BubbleGum", MyWriteFontCollection (nullptr for the moment),
DWRITE_FONT_WEIGHT_LIGHT, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL,
16.0f, L"en-us", &MyIDWriteTextFormat);
我使用Arial这样的系统字体没有任何问题。
谢谢你的帮助。
再次阅读后尝试使用DirectX使用自定义字体文件-集合密钥是什么?和自定义字体集合,我已经开始了解如何获得自定义集合。
我修改了微软给出的示例代码,原因如下:
-
在Windows应用商店中,它不允许使用GetModuleHandle。我在ResourceFontFileEnumerator中直接使用了CreateFontFileReference,而不是CreateCustomFontFileReference。
-
它在应用程序中使用字体,但在我的情况下,字体在用户给定的另一个文件中。因此,我使用了一个变通方法,通过ResourceFontContext::CreateFontCollection 将字体的路径列表提供给ResourceFontFileEnumerator
现在,它运行良好。
相关文章:
- Directx 11 - CompileFromFile() is not compiling
- 在 DirectX 11 中从 GPU 读回顶点缓冲区(并获取顶点)
- DirectX 11 如何处理来自 GPU 上的 sharedHandle 的图像
- C++ Visual Studio 错误:名称后跟'::'必须是类或命名空间名称 (DirectX 11)
- DirectX 11 - 点光源阴影
- DirectX 11 -- Hello Triangle 未呈现 -- 原因:运行时库C++多线程
- DirectX 11 引擎在第三次代码改进后没有突然运行,我不知道为什么
- 无法使用 Visual Studio 启动 DirectX 11 可执行文件,生成工作正常
- 如何处理 DirectX 11 驱动程序崩溃
- 如何在 DirectX 11 中绘制/渲染不同的形状
- 在本书的示例代码中"introduction to 3d game programming with directx 11"
- DirectX 11 on Windows 10
- DirectX 11 文件无法打开源文件
- C DirectX 11从第二个顶点缓冲区呈现麻烦
- 如何在 DirectX 11 中使用曲面细分绘制虚线图案 3D 线
- DirectX 11比例纹理2d
- 使用 DirectX 11 插值背景颜色?
- 如何在 DirectX 11 应用程序中提供选择图形适配器的选项?
- Directx 11 - 是将顶点缓冲区中的所有顶点推送到顶点着色器,还是仅编制索引
- 将指定的字体与directx-11一起使用