Time pass by

Sunshine and rain of a developer

DirectX 10 DrawText Disable Depth Buffer. Here’s how to fix it.

Posted by vanguard33 on July 6, 2009

DrawText() is a bitch. It changes device state silently.  You have to use a spirit to save the states before you draw it and reset depth buffer after you draw the text.


void cGraphicsLayer::DrawTextString(int x, int y, 
 D3DXCOLOR color, const TCHAR* strOutput)
{
 m_pFontSprite->Begin(D3DX10_SPRITE_SAVE_STATE);
 RECT rect = {x, y, m_rcScreenRect.right, m_rcScreenRect.bottom};

 m_pFont->DrawText(m_pFontSprite, strOutput, -1, &rect, DT_LEFT|DT_NOCLIP , color);
 m_pFontSprite->End();
}

Here’s how to recover the depth buffer. You need to keep your DepthStencilState and set it with OMSetDepthStencilState


void cGraphicsLayer::ResetDepthBuffer()
{
 m_pDevice->OMSetDepthStencilState(m_pDepthStencilState, 1);
}

Good luck

3 Responses to “DirectX 10 DrawText Disable Depth Buffer. Here’s how to fix it.”

  1. Anonim said

    Thanks ! I have looked for error in my program for almost 5 hour and I think if I wouldn’t found this info I would never find my error. :D

  2. Torteg said

    Thanks! Useful info!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.