SharpText.Core
0.1.1
See the version list below for details.
dotnet add package SharpText.Core --version 0.1.1
NuGet\Install-Package SharpText.Core -Version 0.1.1
<PackageReference Include="SharpText.Core" Version="0.1.1" />
paket add SharpText.Core --version 0.1.1
#r "nuget: SharpText.Core, 0.1.1"
// Install SharpText.Core as a Cake Addin #addin nuget:?package=SharpText.Core&version=0.1.1 // Install SharpText.Core as a Cake Tool #tool nuget:?package=SharpText.Core&version=0.1.1
SharpText
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.
Description
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)
Getting 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.
textRenderer.Draw();
Examples
The Demo App Using Open Sans
Using Amatic SC
Using LeArchitect
Using Sacramento
Using Neon2
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. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.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. |
-
.NETStandard 2.0
- SharpZipLib (>= 1.2.0)
- System.Numerics.Vectors (>= 4.5.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on SharpText.Core:
Package | Downloads |
---|---|
SharpText.Veldrid
This is the Veldrid rendering backend for SharpText; a GPU accelerated text renderer implemented in C# |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.3.1 | 1,788 | 3/14/2022 |
0.3.0 | 870 | 3/14/2022 |
0.2.0 | 1,413 | 1/17/2021 |
0.1.12 | 1,252 | 5/26/2020 |
0.1.11 | 1,210 | 1/31/2020 |
0.1.10 | 1,314 | 1/19/2020 |
0.1.9 | 1,195 | 1/18/2020 |
0.1.8 | 1,165 | 1/18/2020 |
0.1.7 | 1,250 | 1/18/2020 |
0.1.6 | 1,243 | 1/18/2020 |
0.1.5 | 1,230 | 1/18/2020 |
0.1.4 | 993 | 1/17/2020 |
0.1.3 | 868 | 1/17/2020 |
0.1.2 | 876 | 1/17/2020 |
0.1.1 | 999 | 1/12/2020 |