String on a model
- by alecnash
I am trying to put a sting on a Model and I want it to be dynamic. Did some research and came up with drawing the text on the texture and then set it on the model. I use something like this:
 public static Texture2D SpriteFontTextToTexture(SpriteFont font, string text, Color backgroundColor, Color textColor)
        {
            Size = font.MeasureString(text);
            RenderTarget2D renderTarget = new RenderTarget2D(GraphicsDevice, (int)Size.X, (int)Size.Y);
            GraphicsDevice.SetRenderTarget(renderTarget);
            GraphicsDevice.Clear(Color.Transparent);
            Spritbatch.Begin();
            //have to redo the ColorTexture
            Spritbatch.Draw(ColorTexture.Create(GraphicsDevice, 1024, 1024, backgroundColor), Vector2.Zero, Color.White);
            Spritbatch.DrawString(font, text, Vector2.Zero, textColor);
            Spritbatch.End();
            GraphicsDevice.SetRenderTarget(null);
            return renderTarget;
        }
When I was working with primitives and not models everything worked fine because I set the texture exactly where I wanted but with the model (RoundedRect 3d button) it looks like that:
Is there a way to have the text centered only on one side?