【发布时间】:2011-12-08 12:11:40
【问题描述】:
非常简单。我想取一个像“Bananas”这样的字符串,在上面打一个SpriteFont,然后把它渲染到Texture2D,而不是像SpriteBatch允许的那样直接渲染到屏幕上。
我可以这样做吗?或者,我可以使用某种 FBO 式的功能来完成类似的事情吗?
【问题讨论】:
非常简单。我想取一个像“Bananas”这样的字符串,在上面打一个SpriteFont,然后把它渲染到Texture2D,而不是像SpriteBatch允许的那样直接渲染到屏幕上。
我可以这样做吗?或者,我可以使用某种 FBO 式的功能来完成类似的事情吗?
【问题讨论】:
您可以使用 RenderTarget2D 类。 http://msdn.microsoft.com/en-us/library/bb198676.aspx 像这样的:
RenderTarget2D target = new RenderTarget2D(GraphicsDevice, width,height);
GraphicsDevice.SetRenderTarget(target);// Now the spriteBatch will render to the RenderTarget2D
spriteBatch.Begin();
spriteBatch.DrawString();//Do your stuff here
spriteBatch.End();
GraphicsDevice.SetRenderTarget(null);//This will set the spriteBatch to render to the screen again.
//If you are going to create the render target inside the Draw method, do this:
target.Dispose();
【讨论】: