FPS를 출력하기 위해서는 우선 D3D에서 제공하는 폰트 클래스부터 이용하여 문자를 출력한 후에 설명하겠다..

1.  View 클래스에 멤버 변수로 Font Desc 구조체와 실제 등록할 폰트 변수를 선언한다.
CView.cppView 클래스에 멤버변수 선언
public:
 //D3DXFont 관련 변수
 LPD3DXSPRITE  m_pSprite;
 LPD3DXFONT   m_pFont; // 실제 폰트 객체 포인터 ( 생성자에서 NULL 초기화 잊지말자 )
 D3DXFONT_DESC desc; // D3DFont 를 사용하기 위한. 설정
 LPD3DXFONT  m_pFont_Eng8;
 LPD3DXFONT  m_pFont_Eng12;
 LPD3DXFONT  m_pFont_Kor8;
 LPD3DXFONT  m_pFont_Kor12;

2.  폰트 초기화 함수 등록 후 OnInitialize 함수에서 초기화한다.
CView.cppView 클래스에 함수 등록 하여 사용
// 폰트 초기화 함수
void CEx1View::D3DFontInit(void)
{
 this->desc.CharSet = DEFAULT_CHARSET;
 _tcscpy_s(desc.FaceName, _countof(desc.FaceName), _T("tahoma"));
 this->desc.Weight = 500;
 this->desc.Quality = DEFAULT_QUALITY;
 this->desc.MipLevels = D3DX_DEFAULT;
 this->desc.Italic = 0;
 this->desc.OutputPrecision = OUT_DEFAULT_PRECIS;
 this->desc.PitchAndFamily = FF_DONTCARE;
 this->desc.Width = 8;
 this->desc.Height = desc.Width + (int)(desc.Width/2);
 D3DXCreateFontIndirect(this->m_pd3dDevice,&this->desc,&this->m_pFont_Eng8);
 this->desc.Width = 12;
 this->desc.Height = desc.Width + (int)(desc.Width/2);
 D3DXCreateFontIndirect(this->m_pd3dDevice,&this->desc,&this->m_pFont_Eng12);
 this->desc.CharSet = HANGEUL_CHARSET;
 _tcscpy_s(desc.FaceName, _countof(desc.FaceName), _T("한글폰트네임"));
 this->desc.Width = 8;
 this->desc.Height = desc.Width + (int)(desc.Width/2);
 D3DXCreateFontIndirect(this->m_pd3dDevice,&this->desc,&this->m_pFont_Kor8);
 this->desc.Width = 12;
 this->desc.Height = desc.Width + (int)(desc.Width/2);
 D3DXCreateFontIndirect(this->m_pd3dDevice,&this->desc,&this->m_pFont_Kor12);

 //폰트 리소스의 등록
 //1. 현재경로구하기
 TCHAR szModulePath[255*4];
 ZeroMemory(szModulePath, sizeof(szModulePath));
 ::GetModuleFileName(NULL, szModulePath, sizeof(szModulePath));

 // 2. Get Path
 CString strPath = szModulePath;
 int nPos = strPath.ReverseFind(_T('\\'));
 strPath = strPath.Left(nPos+1);
 //폰트등록
 CString tmp = strPath + _T("한글폰트네임.ttf");
 AddFontResource(tmp);
}


void CEx1View::OnInitialUpdate()
{
 //Sprite 의 생성
 D3DXCreateSprite(this->m_pd3dDevice, &this->m_pSprite);  // DX_9.0c ,이상에서는 폰트는 Sprite를 통해서 출력해야함
 //D3DXFont 클래스의 초기화
 this->D3DFontInit();
 }

실제 위 함수에서는 폰트파일이 Font 폴더에 없을경우 함께 배포하게 될때 사용되는 AddFontResource도 넣어뒀다.



3. 종료시 FontResource 의 해제
CView.cppCleanUp() 에 넣어서 함께 처리
 //폰트 리소스의 해제
 //1. 현재경로구하기
 TCHAR szModulePath[255*4];
 ZeroMemory(szModulePath, sizeof(szModulePath));
 ::GetModuleFileName(NULL, szModulePath, sizeof(szModulePath));
 // 2. Get Path
 CString strPath = szModulePath;
 int nPos = strPath.ReverseFind(_T('\\'));
 strPath = strPath.Left(nPos+1);
 //폰트해제
 CString tmp = strPath + _T("한글폰트네임.ttf");
 RemoveFontResource(tmp);



4.  실제 폰트의 Draw 부분
CXXXView.cppDrawFont
//폰트관련 
#define ENG8 0
#define ENG12 1
#define KOR8 2
#define KOR12 3

// 폰트출력
void CEx1View::DrawFont(const CString& str,int SelectFont, int DestX, int DestY, int Width, int Height,UINT format, D3DCOLOR Color)
{
 RECT rect;
 SetRect(&rect,DestX,DestY,DestX+Width,DestY+Height);
 
 switch(SelectFont)
 {
  case ENG8:
   this->m_pFont = this->m_pFont_Eng8;
   break;
  case ENG12:
   this->m_pFont = this->m_pFont_Eng12;
   break;
  case KOR8:
   this->m_pFont = this->m_pFont_Kor8;
   break;
  case KOR12:
   this->m_pFont = this->m_pFont_Kor12;
   break;
 }
 this->m_pFont->DrawText(this->m_pSprite,LPCTSTR(str),-1,&rect,format,Color);
}
















내가 듣고싶은 음악
내가 들려주고싶은 음악