static void Main() { using (var window = new LayeredRenderWindow() { Text = "Hello World", DragMoveEnabled = true }) { var bottomRightFont = new DWrite.TextFormat(window.XResource.DWriteFactory, "Consolas", 16.0f) { FlowDirection = DWrite.FlowDirection.BottomToTop, TextAlignment = DWrite.TextAlignment.Trailing, }; var bottomLeftFont = new DWrite.TextFormat(window.XResource.DWriteFactory, "Consolas", DWrite.FontWeight.Normal, DWrite.FontStyle.Italic, 24.0f) { FlowDirection = DWrite.FlowDirection.BottomToTop, TextAlignment = DWrite.TextAlignment.Leading, }; window.Draw += Draw; RenderLoop.Run(window, () => window.Render(1, 0)); void Draw(RenderWindow _, Direct2D.DeviceContext target) { XResource res = window.XResource; target.Clear(Color.Transparent); RectangleF rectangle = new RectangleF(0, 0, target.Size.Width, target.Size.Height); target.DrawRectangle( rectangle, res.GetColor(Color.Blue)); target.DrawText("ππππ€£πππ πππππ", res.TextFormats[36], rectangle, res.GetColor(Color.Blue), Direct2D.DrawTextOptions.EnableColorFont); target.DrawText($"{window.XResource.DurationSinceStart:mm':'ss'.'ff}\nFPS: {window.RenderTimer.FramesPerSecond:F1}", bottomRightFont, rectangle, res.GetColor(Color.Red)); target.DrawText("Hello World", bottomLeftFont, rectangle, res.GetColor(Color.Purple)); } } }
protected override void OnDraw(DeviceContext renderTarget) { base.OnDraw(renderTarget); if (!Context.GameOver && Context.CurrentPrize != null) { renderTarget.Transform = GlobalTransform; renderTarget.DrawText( $"{Context.WinPersons.Count}/{Context.CurrentPrize.Count}", XResource.TextFormats[24.0f], new RectangleF(1672.0f, 1957.0f, 100.0f, 30.0f), XResource.GetColor(Color.Yellow)); } }
private void DrawDiagnostics(DeviceContext renderTarget) { renderTarget.Transform = Matrix3x2.Identity; Matrix3x2 wt = GlobalTransform; wt.Invert(); var worldPos = Matrix3x2.TransformPoint(wt, MouseClientPosition); renderTarget.DrawText( $"FPS: {RenderTimer.FramesPerSecond:0}\r\nFrameTime: {RenderTimer.DurationSinceLastFrame}\r\n({worldPos.X:0}, {worldPos.Y:0})", XResource.TextFormats[11], new RectangleF(0, 0, 100, 30), XResource.GetColor(Color.White)); }
protected override void OnDraw(ID2D1DeviceContext renderTarget) { base.OnDraw(renderTarget); renderTarget.Clear(ClearColor); renderTarget.Transform = GlobalTransform; foreach (var sprite in Sprites.Values) { sprite.Draw(renderTarget); } renderTarget.Transform = Matrix3x2.Identity; if (ShowFPS) { renderTarget.DrawText($"FPS: {RenderTimer.FramesPerSecond:F1}", XResource.TextFormats[12.0f], new RectangleF(0, 0, renderTarget.Size.Width, renderTarget.Size.Height), XResource.GetColor(Color4.DimGray)); } }
static void Main() { using (var res = new XResource()) using (var form = new Form() { Text = "Hello World" }) { var timer = new RenderTimer(); var bottomRightFont = new DWrite.TextFormat(res.DWriteFactory, "Consolas", 16.0f) { FlowDirection = DWrite.FlowDirection.BottomToTop, TextAlignment = DWrite.TextAlignment.Trailing, }; var bottomLeftFont = new DWrite.TextFormat(res.DWriteFactory, "Consolas", DWrite.FontWeight.Normal, DWrite.FontStyle.Italic, 24.0f) { FlowDirection = DWrite.FlowDirection.BottomToTop, TextAlignment = DWrite.TextAlignment.Leading, }; form.Resize += (o, e) => { if (form.WindowState != FormWindowState.Minimized && res.DeviceAvailable) { res.Resize(); } }; RenderLoop.Run(form, () => Render()); void Render() { if (!res.DeviceAvailable) { res.InitializeDevice(form.Handle); } var target = res.RenderTarget; timer.BeginFrame(); target.BeginDraw(); Draw(target); target.EndDraw(); res.SwapChain.Present(1, 0); timer.EndFrame(); } void Draw(DeviceContext target) { target.Clear(Color.CornflowerBlue.ToColor4()); RectangleF rectangle = new RectangleF(0, 0, target.Size.Width, target.Size.Height); target.DrawRectangle( new RectangleF(10, 10, target.Size.Width - 20, target.Size.Height - 20), res.GetColor(Color.Blue)); target.DrawText("ππππ€£πππ πππππ", res.TextFormats[36], rectangle, res.GetColor(Color.Blue), DrawTextOptions.EnableColorFont); target.DrawText("FPS: " + timer.FramesPerSecond.ToString("F1"), bottomRightFont, rectangle, res.GetColor(Color.Red)); target.DrawText("Hello World", bottomLeftFont, rectangle, res.GetColor(Color.Purple)); } } }