System fonts

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
REAPER

System fonts

Post by REAPER »

WHY Irrlicht engine don't support system fonts. Two years ago I began to write a game, but not finished it. In it I implemented using of system fonts in DirectX (I don't know OpenGL).
I hope that Niko will implement system fonts:

///////////////CSystemFont.h/////////////////////////

class DLLEXPORT CSystemFont
{
private:

D3DCOLOR Color;
LPD3DXFONT pFont;
RECT Rect;
bool bInitialized;

LPDIRECT3DDEVICE8 m_pD3D_Device;

public:

CSystemFont(void);
~CSystemFont(void);

void Init(LPDIRECT3DDEVICE8 pD3D_Device, HFONT, D3DCOLOR, int x, int y);
void SetColor(D3DCOLOR);
void SetPosition(int, int);
void Print(char *);
void Restore(void);


};

///////////CSystemFont.cpp///////////////////

CSystemFont::CSystemFont(void)
{
SAFE_RELEASE(pFont);
}

CSystemFont::~CSystemFont(void)
{
SAFE_RELEASE(pFont);
SAFE_RELEASE(m_pD3D_Device);
}

void CSystemFont::Init(LPDIRECT3DDEVICE8 pD3D_Device, HFONT in_hFont, D3DCOLOR in_Color, int in_x, int in_y)
{
HRESULT hr;
if (!pD3D_Device)
Except(999, "Invalid Direct3D device passed in", "CSystemFont::Init()");

m_pD3D_Device = pD3D_Device;

hr = D3DXCreateFont(m_pD3D_Device, in_hFont, &pFont);
if (FAILED(hr))
Except(999, "Failed to create D3D font", "CSystemFont::Init()");

Color = in_Color;
bInitialized = true;

Rect.left = in_x;
Rect.top = in_y;
Rect.right = 0;
Rect.bottom = 0;

};

void CSystemFont::SetColor(D3DCOLOR in_Color)
{
Color = in_Color;
};

void CSystemFont::SetPosition(int in_x, int in_y)
{
Rect.left = in_x;
Rect.top = in_y;
};

void CSystemFont::Print(char *in_text)
{
if (!bInitialized) return Except(999, "Failed to print text because the font wasn't initialized", "CSystemFont::Print");

pFont->Begin();
pFont->DrawTextA(in_text, -1, &Rect, 0, Color);
pFont->End();
};

void CSystemFont::Restore (void)
{
pFont->OnLostDevice();
pFont->OnResetDevice();
};



AND how to use this code:

//////////Main.cpp////////////////

CSystemFont test_font;

HFONT hFont = CreateFont(
10, // nHeight //
0, // nWidth //
0, // nEscapement //
0, // nOrientation //
FW_EXTRABOLD, // nWeight //
false, // bItalic //
false, // bUnderline //
0, // cStrikeOut //
ANSI_CHARSET, // nCharSet //
OUT_DEFAULT_PRECIS, //nOutPrecision //
CLIP_DEFAULT_PRECIS, // nClipPrecision //
PROOF_QUALITY, // nQuality //
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily //
"Verdana"); // font name //

test_font.Init(D3DDevice8Obj, hFont, D3DCOLOR_ARGB(255, 255, 255, 255), 5, 5);

Then in loop we call test_font.Restore() before BeginScene func.
beginScene();
test_font.Print("IRRLICHT!!!!!!!!!!!!!!!!!!!");
endScence();
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

It currently it doesn't, because it is a lot work to make this work with both D3D and OpenGL, and Windows and Linux. But it is indeed a cool feature, and on my TODO-list, but has no high priority.
REAPER

System fonts

Post by REAPER »

But, at first you can implement it in DirectX under the Windows and in the next releases you can finish work on it.
Marc
Posts: 25
Joined: Wed Feb 11, 2004 1:03 pm
Contact:

Re: System fonts

Post by Marc »

REAPER wrote:But, at first you can implement it in DirectX under the Windows and in the next releases you can finish work on it.
lol
2D-Splatter-Action => http://www.walkover.de.vu <=
Post Reply