I am starting learning SL5 and 3D API. Can Anyone help with such issue: I am creating 3D object for example Cube and want to display Text there.开发者_开发问答 How can i do this? Can i display text or i need to use images everywhere?
Thanks,
Dima.
as far as i know, there is no api in sl5 designed for making texts in 3d scene. however, there is an alternative to do that by using an object called spritebatch. spritebatch is an efficient class in xna, at the moment it has been integrated in sl5 also. so, to show some texts, you need to 1) draw texts on canvas 2) turn the canvas to a writeablebitmap, and 3) map this writeablebitmap to spritebatch which can be customised by designing two triangles as a plane. below is an example of using spritebatch drawing texts that are on the mytexture.
private void DrawingSurface_Draw(object sender, DrawEventArgs e)
{
//Thread.Sleep(50);
e.GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, new Microsoft.Xna.Framework.Color(0, 0, 0, 0), 1.0f, 0);
spriteBatch.Begin(e.GraphicsDevice);
spriteBatch.Draw(myTexture, new Vector2(0, 0), null, Microsoft.Xna.Framework.Color.White);
spriteBatch.Draw(myTexture, new Microsoft.Xna.Framework.Rectangle(150, 0,100,100), null, Microsoft.Xna.Framework.Color.White);
spriteBatch.Draw(myTexture, new Microsoft.Xna.Framework.Rectangle(250, 0, 50, 50), null, Microsoft.Xna.Framework.Color.White);
spriteBatch.Draw(myTexture, new Microsoft.Xna.Framework.Rectangle(150, 150, 200, 200), new Microsoft.Xna.Framework.Rectangle(0, 0, 100, 100), Microsoft.Xna.Framework.Color.White);
spriteBatch.End();
精彩评论