Just in case anybody else is wondering how to draw text at a 3d position in the world which gets occluded by geometry, here is a little function I wrote:
| public void DrawText(Camera camera, string text, Vector3 position, Color color) |
| { |
| Vector3 screenPos = camera.Viewport.Project(position, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity); |
| |
| spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None); |
| RenderState renderState = Game.Instance.GraphicsDevice.RenderState; |
| renderState.DepthBufferEnable = true; |
| renderState.DepthBufferWriteEnable = false; |
| spriteBatch.DrawString(font, text, new Vector2(screenPos.X, screenPos.Y), color, 0, Vector2.Zero, 1, SpriteEffects.None, screenPos.Z); |
| spriteBatch.End(); |
| } |
| |
Hope it's helpful. I used a few classes from my own game (Camera, Game.Instance) but it should be pretty self explanatory where the variables came from.