Real-time 2D rendering utilities based on Vortice.Windows/Direct2D.
Real-time 2D rendering utilities based on SharpDX/Direct2D.
Package | runtimes | NuGet Package |
---|---|---|
FlysEngine |
net6 |
|
FlysEngine.Desktop |
net6 |
|
FlysEngine.Sprites |
net6 |
(Refer to /tree/master/FlysTest)
FlysEngine
nuget packageSharpDX.Desktop
nuget package for convenientProgram.cs
file, using following namespaces:
using FlysEngine;
using FlysEngine.Desktop;
using FlysEngine.Managers;
using Vortice.Direct2D1;
using Vortice.DirectWrite;
using Vortice.Mathematics;
using FlowDirection = Vortice.DirectWrite.FlowDirection;
using FontStyle = Vortice.DirectWrite.FontStyle;
using (var res = new XResource())
using (var form = new Form() { Text = "Hello World" })
{
var timer = new RenderTimer();
IDWriteTextFormat bottomRightFont = res.DWriteFactory.CreateTextFormat("Consolas", 16.0f);
bottomRightFont.FlowDirection = Vortice.DirectWrite.FlowDirection.BottomToTop;
bottomRightFont.TextAlignment = TextAlignment.Trailing;
IDWriteTextFormat bottomLeftFont = res.DWriteFactory.CreateTextFormat("Consolas", FontWeight.Normal, Vortice.DirectWrite.FontStyle.Italic, FontStretch.Normal, 24.0f);
bottomLeftFont.FlowDirection = Vortice.DirectWrite.FlowDirection.BottomToTop;
bottomLeftFont.TextAlignment = 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(ID2D1DeviceContext target)
{
target.Clear(Colors.CornflowerBlue);
Rect rectangle = new Rect(0, 0, target.Size.Width, target.Size.Height);
target.DrawRectangle(
new Rect(10, 10, target.Size.Width - 20, target.Size.Height - 20),
res.GetColor(Colors.Blue));
target.DrawText("😀😁😂🤣😃😄😅😆😉😊😋😎",
res.TextFormats[36], rectangle, res.GetColor(Colors.Blue),
DrawTextOptions.EnableColorFont);
target.DrawText("FPS: " + timer.FramesPerSecond.ToString("F1"),
bottomRightFont, rectangle, res.GetColor(Colors.Red));
target.DrawText("Hello World",
bottomLeftFont, rectangle, res.GetColor(Colors.Purple));
}
}
Apache License 2.0