By
RoverTurbo
Font creation and function code in d3d.
Code:
#include <stdarg.h>
#include <stdio.h>
LPD3DXFONT oFont;
bool bCreateFont = true;
void TEXT(LPD3DXFONT oFont, int iX, int iY, int iA, int iR, int iG, int iB, const char *cText, ...)
{
D3DCOLOR oColour = D3DCOLOR_ARGB(iA, iR, iG, iB);
RECT rPostion;
rPostion.left = iX;
rPostion.right = rPostion.left + 1001;
rPostion.top = iY;
rPostion.bottom = rPostion.top + 1001;
char cVar[101] = "";
va_list pArgs;
va_start(pArgs, cText);
_vsnprintf((cVar + strlen(cVar)), (sizeof(cVar) - strlen(cVar)), cText, pArgs);
va_end(pArgs);
oFont->DrawText(cVar, -1, &rPosition, 0, oColour);
}
HRESULT APIENTRY IDirect3DDevice9::BeginScene()
{
if(bCreateFont == true)
{
bCreateFont = false;
HFONT hFont = CreateFont(15, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET, 0, 0, PROOF_QUALITY, 0, "Arial Black");
D3DXCreateFont(Device, hFont, &oFONT);
}
return Device->BeginScene();
}
Resetting a font object.
Code:
HRESULT APIENTRY IDirect3DDevice9::Reset(D3DPRESENT_PARAMETERS *pPresentationParameters)
{
if(oFont)
oFont->OnLostDevice();
HRESULT hRet = Device->Reset(pPresentationParameters);
if(oFont)
oFont->OnResetDevice();
return hRet;
}
Credits: Msdn, Google, Directx documentation and Directx Community.