protected override void DrawText(Object dev, String text, String text2 = null, int alpha = 0) { Texture2D texture = (Texture2D)dev; SlimDX.Direct3D10.Device device = texture.Device; #region Save BlendState. Maybe can be done with less code? BlendState bs = device.OutputMerger.BlendState; Color4 bf = device.OutputMerger.BlendFactor; int bsm = device.OutputMerger.BlendSampleMask; int dsr = device.OutputMerger.DepthStencilReference; DepthStencilState dss = device.OutputMerger.DepthStencilState; #endregion if (_font == null) { _sprite = new Sprite(device, 256); _font = new SlimDX.Direct3D10.Font(device, _fd); } _sprite.Begin(SpriteFlags.None); _font.Draw(_sprite, text, new System.Drawing.Rectangle(0, 0, texture.Description.Width, texture.Description.Height), FontDrawFlags.Top | FontDrawFlags.Right | FontDrawFlags.NoClip, System.Drawing.Color.Red); if (alpha > 0) { Color c = Color.FromArgb(alpha, System.Drawing.Color.Red); _font.Draw(_sprite, text2, new System.Drawing.Rectangle(0, 15, texture.Description.Width, texture.Description.Height - 15), FontDrawFlags.Top | FontDrawFlags.Right | FontDrawFlags.NoClip, c); } _sprite.End(); #region Restore Blend State device.OutputMerger.BlendState = bs; device.OutputMerger.DepthStencilState = dss; device.OutputMerger.BlendSampleMask = bsm; device.OutputMerger.BlendFactor = bf; device.OutputMerger.DepthStencilReference = dsr; #endregion }
public void Run() { Device device; SwapChain swapChain; RenderTargetView renderTarget; EmptyWindow.CreateDeviceSwapChainAndRenderTarget(mForm, out device, out swapChain, out renderTarget); // buffer size 1 .. 4096 (0 defaults to 4096) var sprite = new Sprite(device, 10); var font = new Font(device, 20, "ARIAL"); Application.Idle += delegate { device.ClearRenderTargetView(renderTarget, new Color4(1, 0, 0)); var rectangle = new Rectangle(10, 10, 400, 300); sprite.Begin(SpriteFlags.None); font.Draw(sprite, "Hello from SlimDX", rectangle, FontDrawFlags.Left, (uint)Color.Yellow.ToArgb()); sprite.End(); swapChain.Present(0, PresentFlags.None); Application.DoEvents(); }; Application.Run(mForm); }
private void renderDebugOutput() { int i = 0; foreach (var item in DebugOutput) { int y = (i * 20 + 30) % renderFrame.ClientSize.Height - 20; int x = (i * 20 + 30) / renderFrame.ClientSize.Height; var rect = new Rectangle(10 + x * 200, y, 200, 20); debugFont.Draw( null, item.Key + ": " + item.Value, rect, FontDrawFlags.Left, debugColor); ++i; } }
private void DrawText(SlimDX.Direct3D10.Font font, Vector2 pos, string text, Color4 color) { font.Draw(null, text, new System.Drawing.Rectangle((int)pos.X, (int)pos.Y, 0, 0), SlimDX.Direct3D10.FontDrawFlags.NoClip, color); }