Direct3D 9学习笔记(9)文本绘制
2012-08-10 13:26 Clingingboy 阅读(677) 评论(0) 编辑 收藏 举报
一.使用ID3DXFont接口
创建一个ID3DXFont对象
D3DXFONT_DESC df;
ZeroMemory(&df, sizeof(D3DXFONT_DESC));
df.Height = 25; // in logical units
df.Width = 12; // in logical units
df.Weight = 500; // boldness, range 0(light) - 1000(bold)
df.Italic = false;
df.CharSet = DEFAULT_CHARSET;
df.OutputPrecision = 0;
df.Quality = 0;
df.PitchAndFamily = 0;
strcpy(df.FaceName, "Times New Roman"); // font style
//
// Create an ID3DXFont based on 'lf'.
//
if(FAILED(D3DXCreateFontIndirect(Device, &df, &Font)))
{
}
二.使用ID3DXFont绘制文本
RECT rect = {0, 0, Width, Height};
Font->DrawText(NULL,
FPSString,
-1, // size of string or -1 indicates null terminating string
&rect, // rectangle text is to be formatted to in windows coords
DT_TOP | DT_LEFT, // draw in the top left corner of the viewport
0xffff0000); // black text
三.D3DXCreateText
Creates a mesh containing the specified text, using the font associated with the device context.
//
// Describe the font we want.
//
LOGFONT lf;
ZeroMemory(&lf, sizeof(LOGFONT));
lf.lfHeight = 25; // in logical units
lf.lfWidth = 12; // in logical units
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = 500; // boldness, range 0(light) - 1000(bold)
lf.lfItalic = false;
lf.lfUnderline = false;
lf.lfStrikeOut = false;
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfOutPrecision = 0;
lf.lfClipPrecision = 0;
lf.lfQuality = 0;
lf.lfPitchAndFamily = 0;
strcpy(lf.lfFaceName, "Times New Roman"); // font style
//
// Create the font and select it with the device context.
//
hFont = CreateFontIndirect(&lf);
hFontOld = (HFONT)SelectObject(hdc, hFont);
//
// Create the text mesh based on the selected font in the HDC.
//
D3DXCreateText(Device, hdc, "Direct3D",
0.001f, 0.4f, &Text, 0, 0);
其会返回一个ID3DXMesh,然后调用DrawSubset方法
Device->SetMaterial(&d3d::BLUE_MTRL);
Text->DrawSubset(0);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
2011-08-10 WTL学习笔记(4)控件加强
2011-08-10 WTL学习笔记(5)双缓冲技术和动画(BufferedPaint)