Since XNA & MonoGame only use SpriteFont, it’s not very suitable for Chinese/Japanese fonts which has thousands of characters. So I want to use SharpDX directly to render texts while still use MonoGame for other rendering. Here is my code:
//in Initialize()
width = Window.ClientBounds.Width;
height = Window.ClientBounds.Height;
device = new Device(new Direct3D(), 0, DeviceType.Hardware, Window.Handle,CreateFlags.HardwareVertexProcessing,
new PresentParameters(width, height) { PresentationInterval = PresentInterval.One });
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
device.Clear(ClearFlags.Target, SharpDX.Color.Black, 1.0f, 0);
// Draw a texture in MonoGame
spriteBatch.Begin();
spriteBatch.Draw(texture,new Microsoft.Xna.Framework.Vector2(0,0));
spriteBatch.End();
// Draw a text in SharpDX.Direct3D9
device.BeginScene();
font.DrawText(null, displayText, fontDimension, FontDrawFlags.Center | FontDrawFlags.VerticalCenter, SharpDX.Color.White);
device.EndScene();
device.Present();
base.Draw(gameTime);
}
This code works,but seems they are drawing in turn. In some frames there are only the texture drawn by MonoGame, other frames there are only the text.
Is it possible to use them at the same time? Thanks.