Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

why does calling this function mess up the depth buffer? I read somewhere that it cheekily changes the blend state, but to be totally honest I don't even know what that means. What is it doing, why is it doing it and what should I do about it?

Here is my code... instantiation:

RECT rct;
D3DXCOLOR fontColor = D3DXCOLOR(255,0,0,255);   
LPD3DX10FONT m_font;
LPD3DX10SPRITE m_sprite;

and then...


D3DX10CreateSprite(device, 256, &m_sprite);

and THEN...


std::ostringstream oss;

oss << "This ruins the depth buffer!!!" << agents[0].State();

std::string test = oss.str();

m_font->DrawTextA(m_sprite, test.c_str(), -1, &rct, DT_LEFT|DT_NOCLIP , fontColor);


as a side question, is there a more succinct way I can append variables to the string being written?

share|improve this question
up vote 1 down vote accepted

Let's think what the ID3DX10FONT will need.

To draw texts, you need to use alpha blend(mixing the color you will use with the background color). Drawing letters with white or black background will be odd.

Secondly, where should those letters be placed in the world space? It is a hard question. For texts to be shown in front of your window, DirectX 10 changes the depth buffer state. I cannot say for sure, but I guess DX disables it.

To solve this problem, you should change your blend state and depth stencil state back after you drew texts.

First of all, you should create depth stencil state and blend state for your application.

Secondly, draw texts.

Finally, use ID3D10Device::OMSetDepthStencilState/OMSetBlendState to change back.

share|improve this answer
thanks, that worked. for the record you save the state like this: ID3D10DepthStencilState* dss; UINT foo = 1; device->OMGetDepthStencilState(&dss, &foo); and reset it like this: device->OMSetDepthStencilState(dss, 1); – SirYakalot Dec 17 '11 at 11:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.