My Project
d3dfont.h
1 //-----------------------------------------------------------------------------
2 // File: D3DFont.h
3 //
4 // Desc: Texture-based font class
5 //
6 // Copyright (c) Microsoft Corporation. All rights reserved.
7 //-----------------------------------------------------------------------------
8 #ifndef D3DFONT_H
9 #define D3DFONT_H
10 #include <tchar.h>
11 #include <D3D9.h>
12 
13 
14 // Font creation flags
15 #define D3DFONT_BOLD 0x0001
16 #define D3DFONT_ITALIC 0x0002
17 #define D3DFONT_ZENABLE 0x0004
18 
19 // Font rendering flags
20 #define D3DFONT_CENTERED_X 0x0001
21 #define D3DFONT_CENTERED_Y 0x0002
22 #define D3DFONT_TWOSIDED 0x0004
23 #define D3DFONT_FILTERED 0x0008
24 
25 
26 
27 
28 //-----------------------------------------------------------------------------
29 // Name: class CD3DFont
30 // Desc: Texture-based font class for doing text in a 3D scene.
31 //-----------------------------------------------------------------------------
32 class CD3DFont
33 {
34  TCHAR m_strFontName[80]; // Font properties
35  DWORD m_dwFontHeight;
36  DWORD m_dwFontFlags;
37 
38  LPDIRECT3DDEVICE9 m_pd3dDevice; // A D3DDevice used for rendering
39  LPDIRECT3DTEXTURE9 m_pTexture; // The d3d texture for this font
40  LPDIRECT3DVERTEXBUFFER9 m_pVB; // VertexBuffer for rendering text
41  DWORD m_dwTexWidth; // Texture dimensions
42  DWORD m_dwTexHeight;
43  FLOAT m_fTextScale;
44  FLOAT m_fTexCoords[128-32][4];
45  DWORD m_dwSpacing; // Character pixel spacing per side
46 
47  // Stateblocks for setting and restoring render states
48  LPDIRECT3DSTATEBLOCK9 m_pStateBlockSaved;
49  LPDIRECT3DSTATEBLOCK9 m_pStateBlockDrawText;
50 
51  HRESULT CreateGDIFont( HDC hDC, HFONT* pFont );
52  HRESULT PaintAlphabet( HDC hDC, BOOL bMeasureOnly=FALSE );
53 
54 public:
55  // 2D and 3D text drawing functions
56  HRESULT DrawText( FLOAT x, FLOAT y, DWORD dwColor,
57  const TCHAR* strText, DWORD dwFlags=0L );
58  HRESULT DrawTextScaled( FLOAT x, FLOAT y, FLOAT z,
59  FLOAT fXScale, FLOAT fYScale, DWORD dwColor,
60  const TCHAR* strText, DWORD dwFlags=0L );
61  HRESULT Render3DText( const TCHAR* strText, DWORD dwFlags=0L );
62 
63  // Function to get extent of text
64  HRESULT GetTextExtent( const TCHAR* strText, SIZE* pSize );
65 
66  // Initializing and destroying device-dependent objects
67  HRESULT InitDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice );
68  HRESULT RestoreDeviceObjects();
69  HRESULT InvalidateDeviceObjects();
70  HRESULT DeleteDeviceObjects();
71 
72  // Constructor / destructor
73  CD3DFont( const TCHAR* strFontName, DWORD dwHeight, DWORD dwFlags=0L );
74  ~CD3DFont();
75 };
76 
77 
78 
79 
80 #endif
81 
82 
Definition: d3dfont.h:32