In Andrew's comment on my other question, he noted that it was possible to render text to a Texture2D using the Windows API, instead of drawing the text directly with a SpriteBatch. How is this done? I'm guessing there's an intermediate step before writing the image data to a Texture2D.
I'm asking because this would allow me to render Unicode characters on-the-fly, instead of needing to pre-render all the needed glyphs using a SpriteFont (too many glyphs in Korean and Japanese to make this route infeasible, sadly). Thanks!
Answer
Using some reflection, you can grab the Direct3D surface pointer from a Texture2D. From there, you can use any APIs that can render to a DX surface. I did this recently to host XNA content with WPF's D3DImage (with alpha channel support). DirectWrite can render to a DX surface, and you might even be able to use managed APIs. The DirectX .NET wrappers in that link only support Direct3D 10 and 11, and not Direct3D 9 (which XNA uses AFAIK). However, you still might be able to get it to work. On a side note, if you want to render vector graphics, you may be able to use a similar approach to interoperate with Direct2D. Naturally, none of this will work on any XNA-supported platform other than Windows.
No comments:
Post a Comment