couple of font questions

Started by
10 comments, last by Muhammad Haggag 18 years, 8 months ago
I have two questions regarding fonts. First, D3DXCreateFontIndirect fails with error code -858993460. All of the parameters for the call are valid. Here is the call, made in the classes constructor:

D3DXFONT_DESC Font;
ZeroMemory(&Font, sizeof(Font));

Font.Height = 50;
Font.Width = 0;
Font.Weight = 500;
Font.MipLevels = 1;
Font.CharSet = DEFAULT_CHARSET;
Font.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
Font.OutputPrecision = OUT_DEFAULT_PRECIS;
Font.Quality = DEFAULT_QUALITY;
Font.Italic = FALSE;

lstrcpy(Font.FaceName, "Times New Roman");

//call to constructor
m_pFont = new CSWGFont(m_pD3DDevice, Font);

CSWGFont::CSWGFont(IDirect3DDevice9* pD3DDevice, D3DXFONT_DESC Font)
{
	HRESULT hr;
	m_pD3DDevice = pD3DDevice;
	m_pFont = NULL;
	m_pSprite = NULL;

        //Here's where it fails:
	hr = D3DXCreateFontIndirect( pD3DDevice, &Font, &m_pFont);
	hr = D3DXCreateSprite(m_pD3DDevice, &m_pSprite);
}

Second, while I was compile the code, VC2005 complains that sprintf is deprecated. What is a good substitute for this call:

HRESULT CSWGFont::RenderNumber(float Number, D3DCOLOR Color, int X, int Y)
{
	sprintf(m_String, "%f", Number);
	m_String[8] = '\0';

	RECT m_Rect;

	m_Rect.top = Y;
	m_Rect.bottom = Y + 1;
	m_Rect.left = X;
	m_Rect.right = X + 1;

	return m_pFont->DrawText(m_pSprite, m_String, -1, &m_Rect, DT_NOCLIP, Color);
}

Thanks for anybody that helps, ProgrammingNerd
Advertisement
For the font, try specifying non-zero width. Also, run with the debug runtime and check whether there's interesting debug output. Finally, check what GetLastError returns (Win32 API function).

For sprintf: The new, safe, non-standard versions are prefixed with an underscore, IIRC. i.e. _sprintf. However, it's recommended that you use C++ stringstreams:
#include <sstream>using std::stringstream;using std::string;...stringstream ss;float number = ...;ss<< number;string str = ss.str();


A generic to_string utility can be coded as such:
#include <sstream>template <typename T>std::string to_string(const T& val){    std::stringstream ss;    ss<< val;    return ss.str();}

For the first problem I'd use the debug version of D3DX and see what debug output you get. Nothing leaps to mind unless your device isn't valid at that point.

For the replacement, read the help on sprintf. It should tell you what the recommended replacement is. I don't have VS2005 handy here, but it's probably something like sprintf_s. You could just use CString which isn't dependant on MFC anymore.
Stay Casual,KenDrunken Hyena
Hello,

I'm still having problems with displaying text using ID3DXFont. I keep getting error code -858993460, which doesn't correspond to anything in DX error lookup.

I changed things and recoded it, but I'm still having the same problem. Here it is:

hr = D3DXCreateFont(m_pD3DDevice, 50, 25, 500, 1, false, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Times New Roman", &m_pFont);


I'm pretty sure it is an invalid parameter. I know it is a valid device, because I do other stuff before this with the device, and it works with them. It can't out of memory because I control-alt-delete it and it says I still have 30mb of free ram.

I'm sure you use ID3DXFont. If not, is it a bad thing. In the latest SDK, they use textured quads, right? So, it must be relatively fast?

Thanks for your help, I owe this website alot.
ProgrammingNerd

[edit] I checked all of the debug info. I get nothing. And yes, I compiled with d3dx9d.lib.
Quote:Original post by DrunkenHyena
For the first problem I'd use the debug version of D3DX and see what debug output you get.


Stay Casual,KenDrunken Hyena
If you didn't get it, d3dx9d.lib is the debug version of d3dx. It didn't help me, though, because it didn't return anything. I'm pretty sure that it is an invalid parameter.

If you could post a example of D3DXCreateFont, that would be great.

Thanks a lot,
ProgrammingNerd
I suspect that "Times New Roman" is not a valid name - try "Roman" only or "Arial". If that doesn't work either, keep trying to create a windows font (Win32 API) until you get the parameters right.

No, that didn't help. But I noticed something. In the debug output, unicode support is enabled. Here is the debug output:

'SkepWorks V1_0.exe': Loaded 'C:\SkepWorks V1_0\Debug\SkepWorks V1_0.exe', Symbols loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\ntdll.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\kernel32.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\d3d9.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\d3d8thk.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\gdi32.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\user32.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\msvcrt.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\advapi32.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\rpcrt4.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\version.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\winmm.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\d3dx9d_27.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\dsound.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\ole32.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\dinput8.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\hid.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\setupapi.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\wintrust.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\crypt32.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\msasn1.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\imagehlp.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\ntmarta.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\wldap32.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\samlib.dll', Exports loaded.D3DX: Unicode support: 1'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\usp10.dll', Exports loaded.D3DX: (INFO) Using SSE Instructions'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\wdmaud.drv', Exports loaded.'SkepWorks V1_0.exe': Unloaded 'C:\WINDOWS\SYSTEM32\wdmaud.drv''SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\wdmaud.drv', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\msacm32.drv', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\msacm32.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\midimap.dll', Exports loaded.'SkepWorks V1_0.exe': Loaded 'C:\WINDOWS\SYSTEM32\ksuser.dll', Exports loaded.D3DX: Matrix should be 16-byte aligned for better performanceThe thread 'Win32 Thread' (0x14c) has exited with code 0 (0x0).The thread 'Win32 Thread' (0x808) has exited with code 0 (0x0).The thread 'Win32 Thread' (0x804) has exited with code 0 (0x0).The thread 'Win32 Thread' (0x5f8) has exited with code 0 (0x0).D3DX: MEMORY LEAKS DETECTED: 7 allocations unfreed (134792 bytes)D3DX: Set HKLM\Software\Microsoft\Direct3D\D3DXBreakOnAllocId=0x1 to debugThe program '[1784] SkepWorks V1_0.exe: Native' has exited with code 0 (0x0).


Perhaps it is converting my string to something weird. But I thought that unicode was backward compatible with ansi.

Maybe this will help, thanks for all of your help. You guys are great.
ProgrammingNerd
I just tried your exact parameters in my D3DX code and it works fine.

You can see my code here:
Introduction to D3DXFont.

I would set a breakpoint at that line and then run it in the debugger. Check the value of your device. Step over the line and verify that the hresult really is failing.

Something is definitely wrong, but I don't think it's your parameters.
Stay Casual,KenDrunken Hyena
I should add that I also get that unicode note in the debug output. Also, changing the font name to "NotARealFont" still worked, it just used the system default.
Stay Casual,KenDrunken Hyena

This topic is closed to new replies.

Advertisement