Sign in to follow this  
Machine_1989

ID3DX10Font::DrawText() problem

Recommended Posts

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...

Share this post


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this