Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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!

share|improve this question
    
Google for Sprite Billboarding –  Gustavo Maciel Feb 7 '12 at 1:17
add comment

2 Answers

up vote 3 down vote accepted

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

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.