使用 D3DXFont::DrawText 时,为什么重复文本会渲染到不同纹理的 Z 缓冲区上?

发布于 2024-08-03 09:20:09 字数 679 浏览 5 评论 0 原文

我已经被这个问题绊倒了一段时间,想知道以前是否有人遇到过这个问题。

我正在开发的应用程序分为多个数据图和屏幕底部的单个时间线。每个绘图(实际上是彼此层叠的多个纹理)以及时间线都渲染为单独的纹理。首先渲染时间轴纹理,然后渲染从屏幕顶部到底部的每个绘图纹理。我正在使用 DXUT 和 DirectX9(2009 年 3 月)。

将时间文本添加到时间线纹理后,我注意到每个数据图的标题栏中都重复了该文本。这是显示部分的屏幕截图,它仅显示一个图,但文本在打开的每个图上重复:

看起来它直接与时间线渲染函数中调用的 DrawText 相关。我确实使用相对坐标作为传递给 DrawText 的矩形,但由于我已经将渲染目标设置为所需的纹理,因此它应该只影响当前纹理。并非所有纹理都是随后渲染的。

有没有人在使用 D3DXFont 时遇到过类似的问题?

编辑:经过一些更多的实验,看起来它与 Z 缓冲区有关。通过将 D3DCLEAR_ZBUFFER 添加到每个纹理表面上的透明区域,重复的文本就消失了。虽然这个问题现在似乎被绕过了,但我仍然很好奇为什么在我的 DrawText 调用期间会写入完全独立纹理的 Z 缓冲区。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把人绕傻吧 2024-08-10 09:20:09

Z Buffer 状态是持久的。

例如,

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

两个 Draw 调用将使用相同的深度缓冲区。

DrawText 不会更改您设置的深度缓冲区。它假设你打算做你所做的事情。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文