By
Darkcode
You will need to have this in the top of your file:
Code:
#include "D3DFontEngine.h"
extern CFontEngine *pFont;
Here is the main D3DFontEngine.cpp:
Code:
//
// D3DFontEngine.cpp
#include "D3DFontEngine.h"
#include "D3D9Dev.h"
#include "main.h"
HRESULT CFontEngine::Initialize( D3DXFONT_DESC dDesc, D3DCOLOR FontColor )
{
if( m_pFont )
{
SAFE_RELEASE( m_pFont )
}
D3DXCreateFontIndirect( m_D3Ddev, &dDesc, &m_pFont );
m_FontColor = FontColor;
m_bInitialized = TRUE;
return S_OK;
}
HRESULT CFontEngine::DrawText( char *pString, int x, int y )
{
if( !m_bInitialized )
return E_FAIL;
HRESULT hRetVal;
RECT FontRect = { x, y, 0, 0 };
m_pFont->DrawTextA( NULL, pString, -1, &FontRect, DT_CALCRECT, 0 );
hRetVal = m_pFont->DrawTextA( NULL, pString, -1, &FontRect, m_Align, m_FontColor );
return hRetVal;
}
HRESULT CFontEngine::CleanUpFontStuff( )
{
SAFE_RELEASE( m_pFont )
m_bInitialized = FALSE;
return S_OK;
}
void CFontEngine::InitDesc()
{
pDesc.Height = 16;
pDesc.Width = 0;
pDesc.Weight = FW_BOLD;
pDesc.MipLevels = 1;
pDesc.Italic = TRUE;
pDesc.CharSet = DEFAULT_CHARSET;
pDesc.OutputPrecision = OUT_DEFAULT_PRECIS;
pDesc.Quality = ANTIALIASED_QUALITY;
pDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
strcpy( pDesc.FaceName, "Arial" );
Initialize( pDesc, D3DCOLOR_XRGB( 255, 255, 255 ) );
}
And when you look inside D3DFontEngine.h there is this (just incase you don't got it):
Code:
//
// D3DFontEngine.h
#ifndef _D3DFONTENGINE_H
#define _D3DFONTENGINE_H
#include "main.h"
#include "d3d9.h"
class CFontEngine
{
public:
CFontEngine(IDirect3DDevice9 *pIDirect3DDevice9)
{
m_pFont = 0;
m_FontColor = D3DCOLOR_XRGB( 255, 255, 255 );
m_bInitialized = FALSE;
m_Align = DT_LEFT | DT_WORDBREAK;
m_D3Ddev = pIDirect3DDevice9;
};
~CFontEngine( )
{
if( m_pFont )
{
SAFE_RELEASE( m_pFont )
}
};
HRESULT Initialize( D3DXFONT_DESC dDesc, D3DCOLOR FontColor );
HRESULT DrawText( char *pString, int x, int y );
HRESULT CleanUpFontStuff();
void InitDesc(void);
D3DXFONT_DESC pDesc;
D3DCOLOR m_FontColor;
int m_Align;
LPD3DXFONT m_pFont;
RECT m_FontRect;
BOOL m_bInitialized;
private:
IDirect3DDevice9 *m_D3Ddev;
};
#endif //_D3DFONTENGINE_H
And you can tell these 2 things from it for drawing text...
Color:
Code:
pFont->m_FontColor = D3DCOLOR_XRGB( int r, int b, int g);
And then drawing text:
Code:
pFont->DrawText(char *pString, int x, int y);
So once you got that in mind, lets make our black bordered text:
Code:
void MyDrawText ( int x, int y, char Text, int r, int b, int g)
{
pFont->m_FontColor = D3DCOLOR_XRGB( 0, 0, 0 );
pFont->DrawText(char Text, x, y - 1);
pFont->m_FontColor = D3DCOLOR_XRGB( 0, 0, 0 );
pFont->DrawText(char Text, x, y + 1);
pFont->m_FontColor = D3DCOLOR_XRGB( 0, 0, 0 );
pFont->DrawText(char Text, x - 1, y);
pFont->m_FontColor = D3DCOLOR_XRGB( 0, 0, 0 );
pFont->DrawText(char Text, x + 1, y);
pFont->m_FontColor = D3DCOLOR_XRGB( r, g, b );
pFont->DrawText(char Text, x, y);
}
And to call upon it, heres an example:
Code:
MyDrawText( 10, 65, D3D Tutorial, 255, 255, 255);
Which would yield white text with a black border, and placed at 10, 65.
Enjoy