DIRECTX9自带ID3DXFONT类
内部调用GDI的接口,效率一般,但能够处理一些复杂的字体
HRESULT D3DXCreateFontIndirect( LPDIRECT3DDEVICE9 pDevice, CONST D3DXFONT_DESC * pDesc, LPD3DXFONT * ppFont);
typedef struct D3DXFONT_DESC {
INT Height; UINT Width; UINT Weight; UINT MipLevels; BOOL Italic; BYTE CharSet; BYTE OutputPrecision; BYTE Quality; BYTE PitchAndFamily; TCHAR FaceName[LF_FACESIZE]; } D3DXFONT_DESC, *LPD3DXFONT_DESC;
2绘制
INT ID3DXFont::DrawText(LPD3DXSPRITE pSprite, LPCTSTR pString, INT Count,
LPRECT pRect, DWORD Format, D3DCOLOR Color);
实例:
D3DXFONT_DESC lf; ZeroMemory(&lf, sizeof(D3DXFONT_DESC)); lf.Height = 25; // in logical units lf.Width = 12; // in logical units lf.Weight = 500; // boldness, range 0(light) - 1000(bold) lf.Italic = false; lf.CharSet = DEFAULT_CHARSET; lf.Quality = 0; lf.PitchAndFamily = 0; strcpy(lf.FaceName, "Times New Roman"); // font style // // Create an ID3DXFont based on 'lf'. // if(FAILED(D3DXCreateFontIndirect(Device, &lf, &Font))) { ::MessageBox(0, "D3DXCreateFontIndirect() - FAILED", 0, 0); ::PostQuitMessage(0); } Device->BeginScene(); RECT rect = {0, 0, Width, Height}; Font->DrawText( 0, 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 0xff000000); // black text Device->EndScene();
2采用DIRECT3D绘制方式:
可以采用D3D绘图的方式实现更多的效果