سؤال

I'm trying to figure out how to draw text in 3D.

Right now I have two ways to display stuff onto the screen. One that uses usual 3d space to render the world, and additional render to render the HUD that does it in pretransformed way.

So, ideally I would like a way to do the same for text, to both render a string in 3D (kind of like "billboarding" way) and pretransformed way (as if I was using 2d mode).

The only thing that I was able to find is to use "Mesh.FromText", but it doesn't seem to be what I need. Oh, and also using spritebatch to draw text to a texture, and then using this texture in 3D with alpha blending, but again it seems like a crappy way to do it...

Any ideas?

هل كانت مفيدة؟

المحلول

You can draw with SpriteBatch in 3D space by using a custom effect. This blog post has the details.

It's as simple as passing an effect (like BasicEffect) with the correct transformations set on it to the appropriate overload of SpriteBatch.Begin (this one).

(The text is made up of transparent sprites - so all the usual caveats with drawing with transparency in 3D apply: sort and draw over the opaque, Z-buffered scene, or use alpha-testing.)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top