1:定义:ID3DXFont* g_pFont = NULL;
2:创建对象:
HRESULT hr;
V_RETURN(D3DXCreateFont(pd3dDevice,15,0,FW_BOLD,0,FALSE,DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,L"宋体",&g_pFont)) ;
参数含义:
1:设备指针2:字体逻辑高度3:逻辑宽度,取0使用默认4:字体的粗细,如word中的加粗。
5:字体过滤属性,一般取0. 6:是否为斜体7:字符集合8:指定字符输出精度 9:输出质量
10:字体索引号11:字体名称12:字体指针
3:宏V():返回错误hresult,必须在使用前的函数体里定义: HRESULT hr;
4:OnDestroyDevice中释放:
SAFE_RELEASE( g_pFont );
5: OnLostDevice中:
if( g_pFont )
g_pFont->OnLostDevice();
SAFE_RELEASE( g_pTextSprite );
6:void RenderText()
{
CDXUTTextHelper txtHelper( g_pFont, g_pTextSprite, 15 );
//显示当前Direct3D设备状态和渲染帧速率
txtHelper.Begin();
txtHelper.SetInsertionPos( 5, 5 );
txtHelper.SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 0.0f, 1.0f ) );
txtHelper.DrawTextLine( DXUTGetFrameStats(true) );
txtHelper.DrawTextLine( DXUTGetDeviceStats() );
//显示其他简要信息
txtHelper.SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ) );
txtHelper.DrawTextLine( L"Put whatever misc status here" );
//显示简单帮助文本
const D3DSURFACE_DESC* pd3dsdBackBuffer = DXUTGetBackBufferSurfaceDesc();
txtHelper.SetInsertionPos( 10, pd3dsdBackBuffer->Height-15*6 );
txtHelper.SetForegroundColor( D3DXCOLOR( 1.0f, 0.75f, 0.0f, 1.0f ) );
txtHelper.DrawTextLine( L"Controls (F1 to hide):" );
txtHelper.SetInsertionPos( 40, pd3dsdBackBuffer->Height-15*5 );
txtHelper.DrawTextLine( L"Quit: ESC" );
txtHelper.End();
}
7:OnFrameMove:
//渲染文本
DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
RenderText();
DXUT_EndPerfEvent();