Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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...

rct.left=200;
rct.right=780;
rct.top=200;
rct.bottom=rct.top+20;

D3DX10CreateFont(device, 16, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS,     ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Verdana", &m_font);
D3DX10CreateSprite(device, 256, &m_sprite);

and THEN...

m_sprite->Begin(D3DX10_SPRITE_SAVE_STATE);

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);

m_sprite->End();

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

share|improve this question

1 Answer 1

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); –  Asher Einhorn Dec 17 '11 at 11:10

Your Answer

 
discard

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.