HRESULT D3DXCreateFont( __in LPDIRECT3DDEVICE9 pDevice, __in INT Height, __in UINT Width, __in UINT Weight, __in UINT MipLevels, __in BOOL Italic, __in DWORD CharSet, __in DWORD OutputPrecision, __in DWORD Quality, __in DWORD PitchAndFamily, __in LPCTSTR pFacename, __out LPD3DXFONT *ppFont );
HRESULT D3DXCreateFontIndirect( __in LPDIRECT3DDEVICE9 pDevice, __in const D3DXFONT_DESC *pDesc, __out 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; } D3DXFONT_DESC, *LPD3DXFONT_DESC;
//创建字体 HR( D3DXCreateFont(m_pDevice,30,20,0,D3DX_DEFAULT,false,DEFAULT_CHARSET,OUT_TT_ONLY_PRECIS, DEFAULT_QUALITY,81,TEXT("宋体"),&m_pFont) ); //绘制字体 RECT rect; GetClientRect(m_hwnd,&rect); TCHAR buf[50] = {0}; int nSize = _stprintf(buf,TEXT("FPS:%0.2f"),getFPS(dTime) ); HR( m_pFont->DrawText(NULL,buf,nSize,&rect,DT_RIGHT,D3DCOLOR_XRGB(2,190,100)) ); rect.top = 100; HR( m_pFont->DrawText(NULL,TEXT("不会磨灭的激情forever"),-1,&rect,DT_CENTER,D3DCOLOR_XRGB(200,90,100)) ); rect.top = 200; HR( m_pFont->DrawText(NULL,TEXT("狂傲不羁的少年forever"),-1,&rect,DT_CENTER,D3DCOLOR_XRGB(255,120,10)) );
CreateFont,以及CreateFontIndirect
HRESULT D3DXCreateText( __in LPDIRECT3DDEVICE9 pDevice, __in HDC hDC, __in LPCTSTR pText, __in FLOAT Deviation, __in FLOAT Extrusion, __out LPD3DXMESH *ppMesh, __out LPD3DXBUFFER *ppAdjacency, __out LPGLYPHMETRICSFLOAT pGlyphMetrics );
//创建字体 HFONT hFont; HFONT hFontOld; HDC hdc = CreateCompatibleDC(NULL); hFont = CreateFont(25,12,0,0,500,false,false,false,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,TEXT("宋体") ); hFontOld = (HFONT)SelectObject(hdc,hFont); D3DXCreateText(m_pDevice,hdc,TEXT("不经打击老天真"),0.001f,0.5f,&m_pFontMesh,NULL,NULL); SelectObject(hdc,hFontOld); DeleteObject(hFont); DeleteDC(hdc); //绘制字体 m_pFontMesh->DrawSubset(0);
最终显示效果:
原文:http://blog.csdn.net/ddupd/article/details/35281367