0001: //-----------------------------------------------------------------------------
0002: // File: D3DFont.h
0003: //
0004: // Desc: Texture-based font class
0005: //-----------------------------------------------------------------------------
0006: #ifndef D3DFONT_H
0007: #define D3DFONT_H
0008: #include <tchar.h>
0009: #include <D3D9.h>
0010: 
0011: 
0012: // Font creation flags
0013: #define D3DFONT_BOLD        0x0001
0014: #define D3DFONT_ITALIC      0x0002
0015: #define D3DFONT_ZENABLE     0x0004
0016: 
0017: // Font rendering flags
0018: #define D3DFONT_CENTERED_X  0x0001
0019: #define D3DFONT_CENTERED_Y  0x0002
0020: #define D3DFONT_TWOSIDED    0x0004
0021: #define D3DFONT_FILTERED    0x0008
0022: 
0023: 
0024: 
0025: 
0026: //-----------------------------------------------------------------------------
0027: // Name: class CD3DFont
0028: // Desc: Texture-based font class for doing text in a 3D scene.
0029: //-----------------------------------------------------------------------------
0030: class CD3DFont
0031: {
0032:     TCHAR   m_strFontName[80];            // Font properties
0033:     DWORD   m_dwFontHeight;
0034:     DWORD   m_dwFontFlags;
0035: 
0036:     LPDIRECT3DDEVICE9       m_pd3dDevice; // A D3DDevice used for rendering
0037:     LPDIRECT3DTEXTURE9      m_pTexture;   // The d3d texture for this font
0038:     LPDIRECT3DVERTEXBUFFER9 m_pVB;        // VertexBuffer for rendering text
0039:     DWORD   m_dwTexWidth;                 // Texture dimensions
0040:     DWORD   m_dwTexHeight;
0041:     FLOAT   m_fTextScale;
0042:     FLOAT   m_fTexCoords[128-32][4];
0043:     DWORD   m_dwSpacing;                  // Character pixel spacing per side
0044: 
0045:     // Stateblocks for setting and restoring render states
0046:     LPDIRECT3DSTATEBLOCK9 m_pStateBlockSaved;
0047:     LPDIRECT3DSTATEBLOCK9 m_pStateBlockDrawText;
0048: 
0049: public:
0050:     // 2D and 3D text drawing functions
0051:     HRESULT DrawText( FLOAT x, FLOAT y, DWORD dwColor, 
0052:                       const TCHAR* strText, DWORD dwFlags=0L );
0053:     HRESULT DrawTextScaled( FLOAT x, FLOAT y, FLOAT z, 
0054:                             FLOAT fXScale, FLOAT fYScale, DWORD dwColor, 
0055:                             const TCHAR* strText, DWORD dwFlags=0L );
0056:     HRESULT Render3DText( const TCHAR* strText, DWORD dwFlags=0L );
0057:     
0058:     // Function to get extent of text
0059:     HRESULT GetTextExtent( const TCHAR* strText, SIZE* pSize );
0060: 
0061:     // Initializing and destroying device-dependent objects
0062:     HRESULT InitDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice );
0063:     HRESULT RestoreDeviceObjects();
0064:     HRESULT InvalidateDeviceObjects();
0065:     HRESULT DeleteDeviceObjects();
0066: 
0067:     // Constructor / destructor
0068:     CD3DFont( const TCHAR* strFontName, DWORD dwHeight, DWORD dwFlags=0L );
0069:     ~CD3DFont();
0070: };
0071: 
0072: 
0073: 
0074: 
0075: #endif
0076: 
0077: 
0078: