Jump to content
  • Advertisement
Sign in to follow this  
ProgrammingNerd

couple of font questions

This topic is 4841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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();
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 performance
The 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 debug
The 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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!