Drawing 2D with Direct3D: depth buffering?

A528d11e2590c45b74a53dadde386125
0
Xcrypt 101 Feb 21, 2012 at 16:06

Hey, I’m trying to make my engine support 2D rendering with Direct3D.

I can do that with:

D3DXMatrixOrthoOffCenterLH(&m_MatP2D, 0.0f,1.0f,0.0f,1.0f,0.0f,1.0f);

http://msdn.microsoft.com/en-us/library/windows/desktop/bb205347(v=vs.85).aspx

Now, I would like depth buffering enabled for 2D. But I don’t want it to interfere with the 3D graphics
(2D should always render “on top of” the 3D graphics)

What can I do to achieve that?

2 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 168 Feb 21, 2012 at 17:14

Render the 3D graphics, then clear the depth buffer, and render the 2D graphics.

6837d514b487de395be51432d9cdd078
0
TheNut 179 Feb 21, 2012 at 19:27

You could save on some fillrate by reusing the depth buffer if you deal with opaque overlaps, but quite often I use transparency where I have to use a painters algorithm anyway. In this case I just disable depth reads/writes. Teh google found me this (see DepthEnable / DepthWriteMask).