//----------------------------------------------------------------------------- // 文件: D3DText.h // // 描述: D3DText类的头文件,定义变量,函数。 // // 更新: 2009-03-19 by Ninsun //----------------------------------------------------------------------------- #pragma once #include <d3dx9.h> #pragma comment (lib, "d3d9.lib") #pragma comment (lib, "d3dx9.lib") #include "D3DWindow.h" class D3DText { public: D3DText(LPDIRECT3DDEVICE9 _pd3dDevice); public: ~D3DText(void); public: VOID drawText(LPCTSTR _text, INT x, INT y); private: public: private: LPDIRECT3DDEVICE9 m_pd3dDevice; // D3D设备,用于渲染 LPD3DXFONT m_pFont; // 字体对象 LPD3DXFONT m_pFontBack; // 字体对象 RECT clientRect; // 位置矩阵 }; //----------------------------------------------------------------------------- // 文件: D3DText.cpp // // 描述: 用于在D3D窗口绘制2D字体 // // 更新: 2009-03-19 by Ninsun //----------------------------------------------------------------------------- #include "D3DText.h" //----------------------------------------------------------------------------- // 名称: D3DText() // 描述: 自定义构造函数 //----------------------------------------------------------------------------- D3DText::D3DText(LPDIRECT3DDEVICE9 _pd3dDevice) { m_pd3dDevice = _pd3dDevice; D3DXCreateFont(m_pd3dDevice,0,0,FW_BOLD,0,0,0,0,0,0, TEXT("Arial"), &m_pFont); clientRect.left = 0; clientRect.top = 0; clientRect.right = 0; clientRect.bottom = 0; } D3DText::~D3DText(void) { } //----------------------------------------------------------------------------- // 名称: drawText() // 描述: 绘制文字 //----------------------------------------------------------------------------- VOID D3DText::drawText(LPCTSTR _text, INT _x, INT _y) { clientRect.left = _x; clientRect.top = _y; clientRect.right = WND_WIDTH-_x; clientRect.bottom = WND_HEIGHT-_y; m_pFont->DrawText(NULL, _text, (int)wcslen(_text), &clientRect, DT_LEFT|DT_TOP, D3DCOLOR_XRGB(0,0,0)); }