ID3DX10Font::DrawText() problem

Started by
0 comments, last by Machine_1989 15 years, 7 months ago
Hi Okay, I've been having some trouble getting text to display on the screen (C++/DirectX10). I'm attempting to use the simplest method I know of; using ID3DX10Font. Okay so I prepare it like every tutorial says:

ID3DX10Font *mFont;

D3DX10CreateFont(g_pd3dDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Arial", &mFont);

Then in my render function:

/* Time Stuff */
/* Render mesh's */

// Create a colour for the text
D3DCOLOR fontColor = D3DCOLOR_ARGB(255,255,255,255);   

// Create a rectangle to indicate where on the screen it should be drawn
RECT rct;
rct.left=10;
rct.right=780;
rct.top=10;
rct.bottom=rct.top+20;

// Draw some text
mFont->DrawText(NULL, L"Hello World", -1, &rct, DT_SINGLELINE, fontColor );	// all meshes 'explode'

Everything runs fine without the DrawText call, but when it is called all my meshes 'explode' (see screenshots) but text displays fine. Any ideas why this would be happening? Screenshots: before after Thanks in advance...
Advertisement
Okay, with very thorough trial and error, I have found the problem here. Calling ID3DX10Font::DrawText() screws over your input layout, as well as your DepthStencil State.


You will need to re-set the input layout after your done drawing text
ID3D10Device::IASetInputLayout()
this problem can also be avoided by using a sprite with D3DX10_SPRITE_SAVE_STATE flag


Then there is the DepthStencil State problem (occurs even with D3DX10_SPRITE_SAVE_STATE flag), You need to save the Depth Stencil State after creating it, and Set it again after drawing text.
ID3D10Device::OMGetDepthStencilState()
ID3D10Device::OMSetDepthStencilState()

This topic is closed to new replies.

Advertisement