Drawing 2D with Direct3D: depth buffering?

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


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.

Reedbeta 168 Feb 21, 2012 at 17:14

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

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