HelpFont Controller?

Posts 17 of 7 · Page 1 of 1
Font Controller?


With the problem being one of those that is always reoccurring, I was hoping someone would explain a new method or old method to me..

I've done this plenty of ways, one being just a simple creation method (In Present or EndScene)
Code:
if(MyFont == NULL || !MyFont)
{
    if(!IsBadReadPtr((void*)MyFont, sizeof(MyFont))
         MyFont->Release();

    Created = false;
}
if(!Created)
{
    D3DXCreateFont(....&MyFont);
    Created = true;
}
I have also looked around the forum and talked to some friends and they said to use something that I believe originated from Gellin (Didn't work either)

With pDeviceFontBuffer being defined as: LPDIRECT3DDEVICE9 pDeviceFontBuffer;
Code:
if(pFont == NULL || TabFont == NULL)
	{
		D3DXCreateFontA(.......&pFont);
		D3DXCreateFontA(.......&TabFont);
	}
	else
	{
		if(pDeviceFontBuffer != pDevice)
		{
			pDeviceFontBuffer = pDevice;

			try
			{
				if(pFont != 0 || TabFont != 0){ pFont->Release(); TabFont->Release(); }

			} catch (...) {}

			pFont = 0, TabFont = 0;
			D3DXCreateFontA(......&pFont);
			D3DXCreateFontA(......&TabFont);
		}
	}
After going through these and a few more things I put together off the top of my head, I thought of something that made sense, but still failed. Maybe my logic is wrong here, but I figured that since my text worked perfectly until I joined a game, there was a problem with my Device. Maybe my device changed or was lost somehow (and yes I have Reset hooked). So I figured if I save what ever pDevice is returned in my Reset, i could make a new font from it and it should produce visible text. For some reason it didn't work, maybe me logic is flawed... But give it a look:

Reset: (Setting "Buff" to the reset pDevice, so i can make a font off it)
Code:
HRESULT WINAPI nReset( LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* PresentationParameters )
{
	__asm pushad;
	pFont->OnLostDevice();
	TabFont->OnLostDevice();

	HRESULT rCSetRet = oReset(pDevice, PresentationParameters);

	if(SUCCEEDED(rCSetRet)) pFont->OnResetDevice(), TabFont->OnLostDevice(), Buff = pDevice;
	__asm popad;
    return rCSetRet;
}
EndScene:
Code:
if(pFont)
	{
		pFont->Release();
		TabFont->Release();
		pFont = 0;
		TabFont = 0;
		font = false;
	}
	if(!font)
	{
		if(Buff){
			D3DXCreateFont(Buff...... &TabFont);
			D3DXCreateFont(Buff.......&pFont); 
		}else{
			D3DXCreateFont(pDevice.......&TabFont);
			D3DXCreateFont(pDevice.......&pFont); 
		}
		font = true;
	}
It seems like its not my font going bad, its some other issue that wont show my text... I'v also tried just using a hot-key to re-create the font ingame, but it still refused to show!

Any help or additions would be appreciated! Thank you in advanced.
LOL
This is very easy to fix...
Just check if your font is invalid ( == NULL ) in present, and in reset set it to NULL.
Also use "gellins" method LOL which is used by me without knowing gellin should make it -.-
You simply have 2 devices, if the actual one has been chnaged this means font should get invalid, so recreate the font.
Lol, very easy to fix? I've tried everything you just said, plenty of times. I just tried it again and did exactly what you said to do, still disappears. Seems like my font is valid, it's just something else with the game, I don't expect you to know, thanks for the help anyway!
This method works 200% for me.
Also, what font are you using?

Edit: Try to draw the font and getting its size by a rect pointer.
Check if size is same or 0
I'm using Calbria and Arial
Code:
D3DXCreateFont(Buff, 20, 0, FW_BOLD, 1, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,  ANTIALIASED_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Calbria", &TabFont);
D3DXCreateFont(Buff, 14, 0, FW_BOLD, 1, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,  ANTIALIASED_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Arial", &pFont);
I've also tried drawing it differently also,
Code:
void PrintText(int x, int y, D3DCOLOR col, ID3DXFont *font, char pString[])
{
     RECT FontRect = { x, y, x+sizeof(pString), y+30 }; //30, font size varies
     font->DrawText( NULL, pString, -1, &FontRect, DT_LEFT | DT_WORDBREAK, col);
}
and of course the whole MPGH Copy + Pasted DrawString Function,

Code:
void DrawString(int x, int y, DWORD color, LPD3DXFONT g_pFont, const char *fmt, ...)
{
	RECT FontPos = { x, y, x + 1000, y + 1000 };
	char buf[1024] = {'\0'};
	va_list va_alist;

	va_start(va_alist, fmt);
	vsprintf_s(buf, fmt, va_alist);
	va_end(va_alist);

	g_pFont->DrawText(NULL, buf, -1, &FontPos, DT_NOCLIP, color);
}
nothing has worked, and you want me to compare the sizes of the font? (I don't get what your asking)
ive made this mistake once for Crossfire.
probably not whats wrong with yours cuz you seem good at it.
but my problem was i was drawing the text right in lobby
but in game i was drawing my menu on top of the text.
so i could click the boxes and hacks still worked
i just couldnt read which was which,
Quote Originally Posted by -Bl00d- View Post
ive made this mistake once for Crossfire.
probably not whats wrong with yours cuz you seem good at it.
but my problem was i was drawing the text right in lobby
but in game i was drawing my menu on top of the text.
so i could click the boxes and hacks still worked
i just couldnt read which was which,
I am drawing my menu first, and then my text. I don't believe that is the problem, but hey I'll do some tests to be sure! Thanks for the input! Will post my results soon!
Posts 17 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?