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 <D3D8.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    0x0001
0019: #define D3DFONT_TWOSIDED    0x0002
0020: #define D3DFONT_FILTERED    0x0004
0021: 
0022: 
0023: 
0024: 
0025: //-----------------------------------------------------------------------------
0026: // Name: class CD3DFont
0027: // Desc: Texture-based font class for doing text in a 3D scene.
0028: //-----------------------------------------------------------------------------
0029: class CD3DFont
0030: {
0031:     TCHAR   m_strFontName[80];            // Font properties
0032:     DWORD   m_dwFontHeight;
0033:     DWORD   m_dwFontFlags;
0034: 
0035:     LPDIRECT3DDEVICE8       m_pd3dDevice; // A D3DDevice used for rendering
0036:     LPDIRECT3DTEXTURE8      m_pTexture;   // The d3d texture for this font
0037:     LPDIRECT3DVERTEXBUFFER8 m_pVB;        // VertexBuffer for rendering text
0038:     DWORD   m_dwTexWidth;                 // Texture dimensions
0039:     DWORD   m_dwTexHeight;
0040:     FLOAT   m_fTextScale;
0041:     FLOAT   m_fTexCoords[128-32][4];
0042: 
0043:     // Stateblocks for setting and restoring render states
0044:     DWORD   m_dwSavedStateBlock;
0045:     DWORD   m_dwDrawTextStateBlock;
0046: 
0047: public:
0048:     // 2D and 3D text drawing functions
0049:     HRESULT DrawText( FLOAT x, FLOAT y, DWORD dwColor, 
0050:                       TCHAR* strText, DWORD dwFlags=0L );
0051:     HRESULT DrawTextScaled( FLOAT x, FLOAT y, FLOAT z, 
0052:                             FLOAT fXScale, FLOAT fYScale, DWORD dwColor, 
0053:                             TCHAR* strText, DWORD dwFlags=0L );
0054:     HRESULT Render3DText( TCHAR* strText, DWORD dwFlags=0L );
0055:     
0056:     // Function to get extent of text
0057:     HRESULT GetTextExtent( TCHAR* strText, SIZE* pSize );
0058: 
0059:     // Initializing and destroying device-dependent objects
0060:     HRESULT InitDeviceObjects( LPDIRECT3DDEVICE8 pd3dDevice );
0061:     HRESULT RestoreDeviceObjects();
0062:     HRESULT InvalidateDeviceObjects();
0063:     HRESULT DeleteDeviceObjects();
0064: 
0065:     // Constructor / destructor
0066:     CD3DFont( TCHAR* strFontName, DWORD dwHeight, DWORD dwFlags=0L );
0067:     ~CD3DFont();
0068: };
0069: 
0070: 
0071: 
0072: 
0073: #endif
0074: 
0075: 
0076: