我到底应该如何使用ID3DXFont接口?(Direct3D 11, c++)
How exactly am I supposed to use the ID3DXFont interface? (Direct3D 11, c++)
我知道微软更喜欢人们在游戏中使用Direct2D和DirectWrite来渲染文本,但在Direct3D11中使用这些api可能有点乏味。所以我想使用ID3DXFont接口来渲染文本,但问题是,我不知道如何使用它。
我试着在谷歌上搜索如何使用这个界面的教程,但我真的找不到。
无论如何,下面是我实现接口的尝试。
void Create_Font_Device()
{
D3DPRESENT_PARAMETERS presentation;
IDirect3D9 * FontDeviceDesc = NULL;
IDirect3DDevice9 * FontDevice = NULL;
ZeroMemory(&presentation, sizeof(D3DPRESENT_PARAMETERS));
presentation.SwapEffect = D3DSWAPEFFECT_DISCARD;
presentation.Windowed = TRUE;
FontDeviceDesc = Direct3DCreate9(D3D_SDK_VERSION);
FontDeviceDesc->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
MainWindow,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&presentation,
&FontDevice
);
D3DXCreateFont(
FontDevice,
20,
20,
1,
false,
DEFAULT_CHARSET,
OUT_TT_ONLY_PRECIS,
ANTIALIASED_QUALITY,
DEFAULT_PITCH | FF_DONTCARE,
NULL,
L"Arial",
&Font
);
}
/* The Draw_Text() function is called in my game loop */
void Draw_Text()
{
RECT WindowCoordinates;
WindowCoordinates.left = 200;
WindowCoordinates.right = 200;
WindowCoordinates.top = 200;
WindowCoordinates.bottom = 200;
Font->DrawText(
NULL,
L"FPS: ",
5,
&WindowCoordinates,
DT_TOP,
D3DCOLOR_XRGB(1, 1, 255)
);
}
这段代码是不够的,实际上写任何文本到屏幕上,我到底错过了什么?我应该如何实现ID3DXFont接口?
没有适用于Direct3D 11的D3DXFont版本D3DX11没有字体API,因为你注意到一般的期望是你会使用Direct2D/DirectWrite。
所有版本的D3DX已弃用,包括D3DX9, D3DX10和D3DX11。参见MSDN和没有D3DX的生活
对于Direct3D 11上的简单文本渲染,DirectX工具包中的SpriteFont
类非常易于使用。参见绘图文本教程。
std::unique_ptr<DirectX::SpriteFont> font(new SpriteFont(device, L"myfile.spritefont"));
std::unique_ptr<DirectX::SpriteBatch> spriteBatch(new SpriteBatch(context));
spriteBatch->Begin();
font->DrawString(spriteBatch.get(), L"FPS: ", XMFLOAT2(200,200));
spriteBatch->End();
SpriteFont
是一个简单的位图捕获字体,它非常适合较小的字体,如ASCII或扩展ASCII字符集。它并不特别适合呈现大字体语言(如日语、韩语或中文)或替代书写系统(如阿拉伯语)。在这些情况下,Direct2D/DirectWrite确实是最好的方法。
相关文章:
- Direct3D 11 - HLSL - 获取顶点索引 ID
- 在 Direct3D 12 的描述符范围内设置多个描述符
- 使用 c++/WinRT Direct3D UWP Game DR 模板 Direct X11 的错误消息
- 什么是 Direct3D 12.0 上的"Map Default Buffer"?
- Direct3D和DXGI之间的区别
- tiny_obj_loader到 Direct3D 顶点缓冲区和索引缓冲区数组
- Direct3D typedef usage
- 如何在Direct3d 10中进行纹理混合
- Direct3d 11深度模板 / Alpha混合问题
- 使用CMAKE查找Direct3d 12
- 来自代码采样器的Direct3D(DirectX 9.0)代码示例
- Direct3D:尝试绘制一个三角形,但什么也没显示
- 是否覆盖Direct3D接口
- 将世界、视图和投影矩阵传递到 Direct3D 中的着色器
- 为什么当我尝试重写指向 Direct3D 设备的"EndScene"函数的指针时没有任何反应?
- 什么时候应该调整Direct3D 11后缓冲区的大小,以防止在调整大小时拉伸
- Direct3D 中的 Windows Phone 8 触摸位置
- 通过Winsock发送Direct3D顶点信息
- Direct3D旋转矩阵来自矢量,反之亦然
- Nsight or other Direct3D debbuger/performance analyser for V