Sign in to follow this  
bijan311

[d3d10] Draw Text Messes with depth

Recommended Posts

[size=4][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.[/color][/font]

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

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


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

[color=#333333][font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]Here's my code:[/font][/color]
[CODE]
//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);
GamePaint();
m_pSwapChain->Present(0, 0);
}
//GamePaint Function
void GamePaint()
{
//Draw the models
g_pGame->GetDevice()->IASetInputLayout(g_pInputLayout);
for(auto it = g_pAliens.begin(); it != g_pAliens.end(); it++)
(*it)->Draw();
for(auto it = gMissiles.begin(); it != gMissiles.end(); it++)
(*it)->pModel->Draw();
//Display the health
g_pGame->GetFontSprite()->Begin(D3DX10_SPRITE_SORT_TEXTURE);
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));
g_pGame->GetFontSprite()->End();
}
//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);
if(FAILED(hr))
Error(TEXT("DrawText Failed"));
}
//Draw function
void ModelObject::Draw()
{
//Make sure the mesh is valid
if(!m_pMesh)
return;
//Render the object
D3D10_TECHNIQUE_DESC TechniqueDesc;
m_pTechnique->GetDesc(&TechniqueDesc);
for(UINT p = 0; p < TechniqueDesc.Passes; ++p)
{
m_pTechnique->GetPassByIndex(p)->Apply(0);
//Draw the mesh
m_pMesh->DrawSubset(0);
}
}
[/CODE][/size]

Thank you.

Share this post


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

[CODE]

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

//Draw everything
}
[/CODE] Edited by TiagoCosta

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