evilc

thought id ask another question while im at it. i want to display text on the hud of my 3d engine. i did some searching and came across some of the text components out there and chose the nuclex.fonts componenet (very good imo). this works fine on its own or with other 2d objects (eg. sprites) but if i render any 3d objects, all the 3d objects have z buffer issues.

i noticed this problem when i first introduced sprites into my engine and it was fixed via the spritebatch.begin methods savestatemode parameter. however, this functionality doesnt exist with the nuclex.fonts package, so my 3d objects are all screwed again.

is there another option to prevent this, or can someone tell me how to manually save my renderstate and restore it after rendering my text

one more thing, i tried creating a sprite/text hybrid class where i rendered the text within the spritebatch.begin method, it didnt work unfortunately :/



Re: XNA Framework text mixed with 3d

Lord Zarquon

I'm not sure if this will fix your problem, but I know that drawing sprites alters a few settings on the graphics device that causes 3D rendering to screw up. Try setting these after you've drawn the sprites/text.

graphics.GraphicsDevice.RenderState.DepthBufferEnable = true;
graphics.GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;
graphics.GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap;





Re: XNA Framework text mixed with 3d

Pocketmnky

There was a point where I ran into a similar problem where it seemed like my depthbuffer wasn't working correctly with my 3D objects and text renderer. When I looked into it, I found that I had my text rendering drawing before the 3D objects, so once I swapped their drawing order, everything worked fine.




Re: XNA Framework text mixed with 3d

evilc

hi, thx for the response, but it didnt work unfortunately

upon closer examination of my scene, it looks like the normals have been flipped due to the text being drawn, not the z buffer issue i implied in my first post. still open to suggestions.





Re: XNA Framework text mixed with 3d

evilc

hi pocketmnky, just tried that also with no luck.

from your post im assuming you have your text working in a 3d engine. can i ask what text component you used for that





Re: XNA Framework text mixed with 3d

irishcoder

Could be the devices cull mode needs restoring




Re: XNA Framework text mixed with 3d

Bill Reiss

I've tested the TextSprite class in my XNAStage library mixed with 3D and it looks fine. You can find the project here:

http://www.codeplex.com/xnastage

The TextSample demo in the source code package demonstrates how to use the text support without all of the XnaStage timeline classes.

 






Re: XNA Framework text mixed with 3d

Pocketmnky

evilc,

I rolled my own text engine. It basically takes a font bitmap and xml database of descriptions I get from http://www.angelcode.com/products/bmfont/ and reconstructs the text character by character. It's not very feature-rich but it works.






Re: XNA Framework text mixed with 3d

evilc

thx for the post bill,

i took your textsample code and added a basic cube with good results, however with a more complicated model, i got strange results again, different from before. everything seems to be washed out with white, but one mesh in the model is textured correctly.

i wonder if this is a problem with a model with more than one mesh or texture





Re: XNA Framework text mixed with 3d

Bill Reiss

Did you set SaveStateMode.SaveState when beginning your SpriteBatch and is your 3D draw code somewhere outside of the SpriteBatch.Begin and SpriteBatch.End block I just want to make sure we're not missing anything.

Bill






Re: XNA Framework text mixed with 3d

evilc

yep, good thinking bill, i did forget to set the savestatemode in your code for the spritebatch.begin method and it does work now.

unfortunately, setting the same parameter in my code doesnt work, but at least i can investigate yours further for a solution, thx for your time.





Re: XNA Framework text mixed with 3d

grserwe

I had the same problem using Nuclex fonts. The following render states values need to be set back after drawing the text.

GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace;

GraphicsDevice.RenderState.DepthBufferEnable = true;

GraphicsDevice.RenderState.DepthBufferWriteEnable = true;





Re: XNA Framework text mixed with 3d

areia

 grserwe wrote:

I had the same problem using Nuclex fonts. The following render states values need to be set back after drawing the text.

GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace;

GraphicsDevice.RenderState.DepthBufferEnable = true;

GraphicsDevice.RenderState.DepthBufferWriteEnable = true;



Thanx, that solved the problem here too.