3
\$\begingroup\$

For a 2D overlay in a 3D environment using DirectX, is the 2D overlay still coded as a surface in 3d always positioned in front of the camera?

I haven't tried this yet but I imagine that technique would lead to small jitters as a scene moves, plus lighting weirdness. It would help me to know the correct way before I struggle in the wrong direction.

I'm very new to DirectX and game programming and I have limited experience with the paradigms of unmanaged APIs. I'm using C# with SlimDX. I have a re-organized version of the SlimDX Triangle tutorial working well.

What I read on this site and others regarding DirectX is that DirectX only draws/shades triangles and the rest is up to me.

SlimDX seems to have some stuff in the DirectX2D namespace - RenderTarget, which has a DrawText() method, but I can't figure out how to get such a 2D RenderTarget hooked to my scene to play with it.

Thanks!

\$\endgroup\$
1
  • \$\begingroup\$ Google for Sprite Billboarding \$\endgroup\$ Commented Feb 7, 2012 at 1:17

2 Answers 2

3
\$\begingroup\$

When drawing 2D overlay disable any lighting and depth test. And set camera projection matrix to orthographic, so no jitter will be present - and you will be able to achieve pixel-perfect mapping.

Not sure which version of Direct3D are you using (9/10/11) but here's nice explanation for Direct3D11: http://www.rastertek.com/dx11tut11.html

\$\endgroup\$
2
  • \$\begingroup\$ Could you fix the link, it broke. \$\endgroup\$
    – Skami
    Commented Sep 28, 2014 at 12:39
  • \$\begingroup\$ The link is working, unlike the linked tutorial. While it can render the 2D in ortho projection, it doesn't have a billboard effect at all - moving camera to a side will result in texture shrinking. Looking from behind the 2D will not render it at all. \$\endgroup\$
    – lolbas
    Commented Feb 20, 2019 at 7:07
1
\$\begingroup\$

The key to rendering a UI and it's windows is to use textured quads (two triangles) in screen space (or transformed to screen space using an orthogonal projection instead of your standard perspective projection).

However, to properly do this you will need to disable your depth buffer and render your UI last on top of everything else. This way your quads won't potentially be depth clipped or overwritten in the output merger stage of the pipeline.

And since it's a UI, I expect you want to use it for displaying text too. This is achieved in the same way however it takes a bit more work. First you will need a texture of all your characters. Then for each character, render a quad to the screen and adjust it's UV coordinates in order to have it sample the right character.

I believe DirectX11 has no built in rendering support for text but earlier versions and the DXUT library do. (I think!)

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .