Jump to content


Newbish D3D10 font question


5 replies to this topic

#1 Reedbeta

    DevMaster Staff

  • Administrators
  • 5340 posts
  • LocationSanta Clara, CA

Posted 06 August 2009 - 06:26 AM

I'm teaching myself a little D3D10 in my spare time. Although I'm experienced with OpenGL this is my first time touching any version of D3D, so I'm hitting a few snags. I've got a basic spinning-cube up and running, and now I'm trying to draw text on the screen.

I'm setting up a font object like this:

D3DX10_FONT_DESC fontDesc =
{
	20, // height
	0, // width
	FW_NORMAL, // weight
	1, // mip levels
	false, // italic
	ANSI_CHARSET,
	OUT_DEFAULT_PRECIS,
	DEFAULT_QUALITY,
	FF_DONTCARE,
	L"Arial"
};

if (FAILED(D3DX10CreateFontIndirect(g_pDevice, &fontDesc, &g_pFont)))
{
	ErrorPrintf(L"Could not create font!");
}

This succeeds (I don't see the error message). Then I'm drawing the text like this, right before my Present() call:

RECT rectText = { 10, 10, 100, 100 };

g_pFont->DrawText(NULL, L"test", -1, &rectText, DT_LEFT | DT_TOP | DT_NOCLIP, D3DXCOLOR(1, 1, 1, 1));

However, I don't see any text showing up at all. The DrawText call also returns no error. I haven't quite figured out how to turn on the debug runtime in D3D10 (it's not like D3D9 where you can just click a button in the control panel, but rather application controlled somehow), so I haven't been able to check that yet.

Unfortunately the docs I could find on ID3DX10Font are pretty sketchy, and I've looked at the SDK samples but can't see any material difference between them and what I'm doing (at least on a once-over). Does anyone know something obvious that might be the problem?
reedbeta.com - developer blog, OpenGL demos, and other projects

#2 Goz

    Senior Member

  • Members
  • PipPipPipPip
  • 575 posts

Posted 06 August 2009 - 07:57 AM

From my code I've got the following to set up the debug spew:

#ifdef _DEBUG

	unsigned int flags	= D3D10_CREATE_DEVICE_DEBUG;

#else

	unsigned int flags	= 0;

#endif


	mpAdapter	= vAdapters[selectedAdapter];

	// Create the device and swap chain.

	if ( FAILED( D3D10CreateDeviceAndSwapChain( mpAdapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, flags, D3D10_SDK_VERSION, &dxgiSwapChainDesc, &mpSwapChain, &mpDevice ) ) )

	{

		return false;

	}

BTW im just comparing my working font creation to yours to check for difference.

D3DXCreateFont( ((D3DHandler*)pHandler)->GetDevice(), 16, 8, 8, 0, FALSE, 0, OUT_TT_ONLY_PRECIS, 0, 0, "ARIAL", &g_pFont );

So im using a height of 16 and weight of 8. I have mipLevels set to 0 (ie create all). I have charset set to 0 (No idea why this is) and my qualtiy and pitchandfamily set to 0.

Potentially could your problem be the setting the width to 0? Beyond that guess I'm just not sure.

#3 Reedbeta

    DevMaster Staff

  • Administrators
  • 5340 posts
  • LocationSanta Clara, CA

Posted 06 August 2009 - 04:26 PM

Thanks Goz. The docs on LOGFONT claim width = 0 is supported and means choose the proper width for the aspect ratio of the font and device, and I believe the SDK samples set the width to 0 and miplevles to 1 as well. Nevertheless I'll certainly try that once I get home.
reedbeta.com - developer blog, OpenGL demos, and other projects

#4 Goz

    Senior Member

  • Members
  • PipPipPipPip
  • 575 posts

Posted 06 August 2009 - 06:52 PM

they may be right ... as i say I can't see anything particularly wrong but those things i point out. Try fiddling and see what you can get it to do :)

#5 Reedbeta

    DevMaster Staff

  • Administrators
  • 5340 posts
  • LocationSanta Clara, CA

Posted 07 August 2009 - 03:44 AM

I've solved the problem. The culprit was my rasterizer state block; I set it to treat counterclockwise faces as front, which is what I'm used to, but is apparently contrary to the D3D default. Setting clockwise-front brought the text back.

Incidentally, I found a funky little gotcha...know how the Vista start menu has that little bump that extends a few pixels beyond the taskbar? Well, with my spinning cube, I got frame times of about 0.5 ms, but if I moved the window to put the bump in front of it, my frame times went up to 15 ms! I guess Vista won't draw that bump faster than the refresh rate. I was worried for a bit there when I maximized my window and saw the framerate tank..."it's pixel bound already?!" :D
reedbeta.com - developer blog, OpenGL demos, and other projects

#6 Goz

    Senior Member

  • Members
  • PipPipPipPip
  • 575 posts

Posted 07 August 2009 - 07:07 AM

Oh ... I thought culling the counter clockwise side was always the default ...





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users