-
-
Notifications
You must be signed in to change notification settings - Fork 8
Using NvgSharp in MonoGame or FNA
There are two ways of referencing NvgSharp in the project:
-
Through nuget(works only for MonoGame):
- https://www.nuget.org/packages/NvgSharp.MonoGame/
- https://www.nuget.org/packages/NvgSharp.Text.MonoGame/ (optional reference, if you want the text rendering)
-
As source code(works for all supported engines):
a. Clone this repo.
b. Add src/XNA/NvgSharp.{Engine}.csproj to the solution
c. Optionally add src/NvgSharp.Text/NvgSharp.Text.{Engine}.csproj to the solution, if you want the text rendering.
d. If FNA was used and the NvgSharp.Text.FNA.csproj was referenced, then FontStashSharp should be cloned too. The overall folder structure is expected to be following:
NvgSharp requires Game to be created with stencil. That could be archived by setting PreferredDepthStencilFormat to DepthFormat.Depth24Stencil8 in the GraphicsDeviceManager creation.
I.e.
public Game1()
{
_graphics = new GraphicsDeviceManager(this)
{
PreferredBackBufferWidth = 1000,
PreferredBackBufferHeight = 600,
PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8
};
}
Add following field to the Game class:
private NvgContext _context;
And following code to the LoadContent method:
_context = new NvgContext(GraphicsDevice);
Add following code to Draw method to render a red circle:
_context.FillColor(Color.Red);
_context.Circle(100, 100, 20);
_context.Fill();
_context.Flush();
https://github.com/rds1983/NvgSharp/tree/master/samples/NvgSharp.Samples.Demo