• Advertisement
Sign in to follow this  

[d3d10] Draw Text Messes with depth

This topic is 2066 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif][color=#333333]I want to tell the user his/her health via the DrawText function, but the functions seems to be messing with how the meshes are drawn.[/font]

[color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]For example, the "missiles" look like this:[/font]
[color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]4f9cad7a7ae79.jpg[/font]
[color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]When they should look like this:[/font]
[color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]4f9caeb6b583f.jpg[/font]

[color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]And my "aliens" look like this:[/font]
[color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]4f9cafb39c0ec.jpg[/font]

[color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]Instead of this (ignore the missile) :[/font]
[color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]4f9cb05bed716.jpg[/font]

[color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]Here's my code:[/font]

//Render function
void BimanEngine::Render()
//Clear the render target view
m_pD3DDevice->ClearRenderTargetView(m_pRenderTargetView, D3DXCOLOR(0.02f, 0.04f, 0.2f, 0.0f));
//Clear the depth/stencil view
//m_pD3DDevice->ClearDepthStencilView(m_pDepthStencilView, D3D10_CLEAR_DEPTH|D3D10_CLEAR_STENCIL, 1.0f, 0);
m_pSwapChain->Present(0, 0);
//GamePaint Function
void GamePaint()
//Draw the models
for(auto it = g_pAliens.begin(); it != g_pAliens.end(); it++)
for(auto it = gMissiles.begin(); it != gMissiles.end(); it++)
//Display the health
TCHAR szHealth[64];
wsprintf(szHealth, TEXT("Health: %i"), g_iHealth);
g_pGame->DrawText(szHealth, 10, 10, D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f));
//DrawText function
void BimanEngine::DrawText(LPCWSTR szText, int x, int y, D3DXCOLOR TextColor)
RECT rect = {x, y, 0, 0};
//Display rect
HRESULT hr = m_pFont->DrawText(m_pFontSprite, szText, -1, &rect, DT_NOCLIP, TextColor);
Error(TEXT("DrawText Failed"));
//Draw function
void ModelObject::Draw()
//Make sure the mesh is valid
//Render the object
D3D10_TECHNIQUE_DESC TechniqueDesc;
for(UINT p = 0; p < TechniqueDesc.Passes; ++p)
//Draw the mesh

Thank you.

Share this post

Link to post
Share on other sites
The DrawText() function switches the depth-stencil state, so before drawing anything at the beginning of a frame set the depth stencil state to default:

void GamePaint()
//Set depth stencil state to default
g_pGame->GetDevice()->OMSetDepthStencilState(0, 0);

//Draw everything
Edited by TiagoCosta

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement