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
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
Torteg said
Thanks! Useful info!
Ivan said
THANKS! This really helped.