Why is duplicate text being rendered onto the Z buffer of a different texture when using D3DXFont::DrawText?

StackOverflow https://stackoverflow.com/questions/1358896

  •  20-09-2019
  •  | 
  •  

Question

I've been stumbling over this for a while and was wondering if anyone has run into this problem before.

The application I'm working on is divided into multiple data plots and a single timeline at the bottom of the screen. Each plot (which is actually multiple textures layered on top of each other) as well as the timeline is rendered to a separate texture. The timeline texture is rendered first, followed by each of the plot textures from the top of the screen to the bottom. I am using DXUT and DirectX9 (March 2009).

After adding time text to the timeline texture, I noticed that the text was repeated in the title bar of every data plot. Here's a screencap of a portion of the display, it shows just a single plot, but the text repeats on every plot opened:

alt text

It seems like it is tied directly to the DrawText being called in the timeline's render function. I do use relative coordinates as the rect being passed to DrawText, but since I've already set the render target to the desired texture it should only affect the current texture. Not every texture rendered afterward.

Has anyone ever run into any problems similar to this using D3DXFont?

EDIT: After some more experimentation, it looks like it has something to do with the Z buffer. By adding D3DCLEAR_ZBUFFER to the clear on each texture surface, the duplicate text is gone. While the problem seems bypassed for now, I'm still curious as to why the Z buffer for a completely separate texture was being written during my DrawText call.

Was it helpful?

Solution

The Z Buffer state is persistent.

For example,

SetDepthStencilSurface(X)
SetRenderTarget(A)
Draw()
SetRenderTarget(B)
Draw()

Both Draw calls will use the same depth buffer.

The DrawText is not changing the depth buffer that you have set. It assumes you meant to do what you did.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top