Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/dxgsg8/d3dfont8.h

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------------------------
00002 // File: D3DFont.h
00003 //
00004 // Desc: Texture-based font class
00005 //       based on a modified version of DXSDK CD3DFont from http://www.lafaqmfc.com/directx.htm
00006 //       Note that this is faster than ID3DXFont, which calls GDI in Draw()
00007 //---------------------------------------------------------------------------------------------
00008 #ifndef D3DFONT_H
00009 #define D3DFONT_H
00010 #include <tchar.h>
00011 #include <d3d8.h>
00012 
00013 // Font creation flags
00014 #define D3DFONT_BOLD        0x0001
00015 #define D3DFONT_ITALIC      0x0002
00016 #define D3DFONT_ZENABLE     0x0004
00017 
00018 // Font rendering flags
00019 #define D3DFONT_CENTERED    0x0001
00020 #define D3DFONT_TWOSIDED    0x0002
00021 #define D3DFONT_FILTERED    0x0004
00022 
00023 //-----------------------------------------------------------------------------
00024 // Name: class CD3DFont
00025 // Desc: Texture-based font class for doing text in a 3D scene.
00026 //-----------------------------------------------------------------------------
00027 class CD3DFont
00028 {
00029     enum 
00030     { 
00031         D3DFVF_FONT2DVERTEX = (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1) , 
00032         D3DFVF_FONT3DVERTEX = (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1) , 
00033         TextBufferLength = 1024 , 
00034         MAX_NUM_VERTICES = TextBufferLength * 6 , 
00035         MaxCalls = 30 
00036     } ; 
00037 
00038     TCHAR   m_strFontName[80];            // Font properties
00039     DWORD   m_dwFontHeight;
00040     DWORD   m_dwFontFlags;
00041 
00042     LPDIRECT3DDEVICE8       m_pd3dDevice; // A D3DDevice used for rendering
00043     LPDIRECT3DTEXTURE8      m_pTexture;   // The d3d texture for this font
00044     LPDIRECT3DVERTEXBUFFER8 m_pVB;        // VertexBuffer for rendering text
00045     DWORD   m_dwTexWidth;                 // Texture dimensions
00046     DWORD   m_dwTexHeight;
00047     FLOAT   m_fTextScale;
00048     FLOAT   m_fTexCoords[128-32][4];
00049 
00050     // Stateblocks for setting and restoring render states
00051     DWORD   m_dwSavedStateBlock;
00052     DWORD   m_dwDrawTextStateBlock;
00053 
00054     struct DrawTextArgs 
00055     {
00056         bool  m_bScaled ; 
00057         FLOAT m_x ;  FLOAT m_y ;  FLOAT m_z ; 
00058         FLOAT m_fXScale ; FLOAT m_fYScale ; 
00059         DWORD m_dwColor ;  
00060         TCHAR *m_strText ; 
00061         DWORD m_dwFlags ; 
00062     } ; 
00063 
00064     DrawTextArgs m_DTArgs [ MaxCalls ] ; 
00065     char    m_TextBuffer  [ TextBufferLength ] ; 
00066     char   *m_pTextBuffer ; 
00067     UINT    m_nDeferedCalls ;
00068     bool    m_bBeginText ; 
00069     inline  HRESULT DeferedDrawText( FLOAT x, FLOAT y, DWORD dwColor, 
00070                       TCHAR* strText, DWORD dwFlags=0L );
00071     inline  HRESULT DeferedDrawTextScaled ( FLOAT x, FLOAT y, FLOAT z, 
00072                             FLOAT fXScale, FLOAT fYScale, DWORD dwColor, 
00073                             TCHAR* strText, DWORD dwFlags=0L ) ; 
00074     inline  HRESULT DeferedDraw
00075             ( bool bScaled , 
00076               FLOAT x, FLOAT y, FLOAT z, 
00077               FLOAT fXScale, FLOAT fYScale, DWORD dwColor, 
00078               TCHAR* strText, DWORD dwFlags ) ; 
00079 
00080     inline  void ClearBeginEndData (void ) ; 
00081 
00082 
00083 public:
00084     // 2D and 3D text drawing functions
00085     HRESULT BeginText ( void ) ;
00086     HRESULT EndText ( void ) ;
00087 
00088     HRESULT DrawText( FLOAT x, FLOAT y, DWORD dwColor, 
00089                       TCHAR* strText, DWORD dwFlags=0L );
00090     HRESULT DrawTextScaled ( FLOAT x, FLOAT y, FLOAT z, 
00091                             FLOAT fXScale, FLOAT fYScale, DWORD dwColor, 
00092                             TCHAR* strText, DWORD dwFlags=0L ) ; 
00093 
00094    // HRESULT Render3DText( TCHAR* strText, DWORD dwFlags=0L );
00095     
00096     // Function to get extent of text
00097     HRESULT GetTextExtent( TCHAR* strText, SIZE* pSize );
00098 
00099     // Initializing and destroying device-dependent objects
00100     HRESULT InitDeviceObjects(LPDIRECT3DDEVICE8 pd3dDevice);
00101     HRESULT RestoreDeviceObjects(void);
00102     HRESULT InvalidateDeviceObjects(void);
00103     HRESULT DeleteDeviceObjects(void);
00104 
00105     // Constructor / destructor
00106     CD3DFont( TCHAR* strFontName, DWORD dwHeight, DWORD dwFlags=0L );
00107     ~CD3DFont();
00108 };
00109 
00110 #endif
00111 
00112 

Generated on Fri May 2 00:37:09 2003 for Panda by doxygen1.3