See the version list below for details.
dotnet add package SharpText.Veldrid --version 0.1.5
NuGet\Install-Package SharpText.Veldrid -Version 0.1.5
<PackageReference Include="SharpText.Veldrid" Version="0.1.5" />
paket add SharpText.Veldrid --version 0.1.5
#r "nuget: SharpText.Veldrid, 0.1.5"
// Install SharpText.Veldrid as a Cake Addin #addin nuget:?package=SharpText.Veldrid&version=0.1.5 // Install SharpText.Veldrid as a Cake Tool #tool nuget:?package=SharpText.Veldrid&version=0.1.5
Disclaimer: This project is a work in progress and will most likely have bugs (but it does seem to work OK from my experiences so far). Feel free to give it a go and please raise any bugs or feature requests as an issue on this repo. I would be more than happy to look at any PRs for such improvements.
This is a GPU accelerated text renderer implemented in C#. It implements the excellent technique discussed by Evan Wallace here (thanks to Evan for explaining in detail how the technique works and providing example code 😃 ). It comprises of a few steps:
- Read in a font file in any supported format (I chose the Typography library as it has .NET Standard support)
- Convert the lines and Bezier curves into a set of triangles that can be rendered
- Render the triangles out to a render target
- Run another pass with the render target as input which renders the final text and performs sub-pixel anti-aliasing
It should reusable across rendering platforms as I have seperated out any platform/implementation specific code into different projects.
At the moment, the project structure looks like this:
- SharpText.Core - contains shared logic and platform independant code
- SharpText.Veldrid - implements an ITextRenderer for the Veldrid graphics backend
- SharpText.DemoApp - a simple demo app to show how to use this library (take a look at Program.cs to get started)
First you will need to create a Font object for the font and size you wish to use.
var font = new Font("Fonts/OpenSans-Regular.woff", 20);
Next you need to create a text renderer using an implementation of ITextRenderer.
This example uses the Veldrid renderer. You need to pass in the GraphicsDevice and CommandList you would like to use, and then the font object we just created.
var textRenderer = new VeldridTextRenderer(graphicsDevice, commandList, font);
Now you can start drawing text with this renderer. This statement will draw the string at position X=5,Y=5 in the color Black.
textRenderer.DrawText("The quick brown fox jumps over the lazy dog", new Vector2(5, 5), new Color(0, 0, 0, 1));
Now just call the Draw method as part of your normal draw loop while you have an active CommandList.
The Demo App Using Open Sans
Using Amatic SC
|Product||Versions Compatible and additional computed target framework versions.|
|.NET||net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed.|
|.NET Core||netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed.|
|.NET Standard||netstandard2.0 is compatible. netstandard2.1 was computed.|
|.NET Framework||net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed.|
|MonoAndroid||monoandroid was computed.|
|MonoMac||monomac was computed.|
|MonoTouch||monotouch was computed.|
|Tizen||tizen40 was computed. tizen60 was computed.|
|Xamarin.iOS||xamarinios was computed.|
|Xamarin.Mac||xamarinmac was computed.|
|Xamarin.TVOS||xamarintvos was computed.|
|Xamarin.WatchOS||xamarinwatchos was computed.|
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.