This project is read-only.
2
Vote

Depth Buffer with 3D Text (Text Batch)

description

I'm trying to draw a 3D text with some other 3D objects and spritebatch for 2D drawings
So my draw function looks like this
 
Text Batch Drawings (3D text)
3D Drawings
Sprite Batch Drawings (2D Drawings)
 
I've a problem with the depth buffer as the 3d drawings always appears in front of the 3D text
and If I interchanged the 3D text drawing with the 3D drawings the text always appears in front of the 3D objects
 
I tried to to enable the depth buffer but it affects the 3d objects only
 
here is my drawing code

 

 
        GraphicsDevice.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true };
 
        // 3d drawing
        G.Draw();
        this.E1.Draw();
        this.axis.draw(this.GraphicsDevice);
 
        // 3d text
        this.textBatch.Begin();
        this.textBatch.ViewProjection = Camera.View * Camera.Projection;
        Matrix textWorld = Matrix.CreateScale(new Vector3(1.0f, 1.0f, 5.0f)) * Matrix.CreateTranslation(new Vector3(0.0f, 0.0f, 0.0f));
        this.textBatch.Begin();
        this.textBatch.DrawText(this.label, textWorld, Color.Black);
        this.textBatch.End();
 
        // 2d drawing
        this.spriteBatch.Begin();
        this.spriteBatch.Draw(this.target, new Rectangle(Mouse.GetState().X - 9, Mouse.GetState().Y - 9, 18, 18), Color.White);
        this.spriteBatch.Draw(this.gameHud, new Rectangle(0, this.GraphicsDevice.Viewport.Height - 60, this.GraphicsDevice.Viewport.Width, this.GraphicsDevice.Viewport.Height), Color.White);
        this.spriteBatch.DrawString(this.mySpriteFont, this.gameName, new Vector2(5.0f, 0.0f), Color.Black);
        this.spriteBatch.DrawString(this.mySpriteFont, this.nodeIndex, new Vector2(50.0f, 50.0f), Color.Black);
        this.spriteBatch.End();

 

 
G, E1 and Axis are objects that draw themselves and they work correctly independent of the 3D text

file attachments

comments

miklos_albert wrote Jan 14, 2013 at 10:48 AM

the text should be on the grid, in front of the zombie. the description of the issue is the same as above.

Cygon wrote Jan 18, 2013 at 2:17 PM

Not a bug.

It is up to you whether the text writes to the depth buffer or not. The default shader will not write to the Z Buffer: https://devel.nuclex.org/framework/browser/graphics/fonts/Nuclex.Fonts/trunk/Source/Effects/SolidColorEffect.cs

The usage I had envisioned for 3D text were classic movie titles/credits that appear at relatively large sizes on the screen but which do not interact with the 3D scene (and are rendered last, on top of everything else).

If you want the text to be able to obscure other scenery or be obscured by it, use your own Effect with ZWriteEnable = true (there's an overload for TextBatch.DrawText() which accepts a custom Effect).

wrote Feb 22, 2013 at 12:26 AM