-
-
Notifications
You must be signed in to change notification settings - Fork 8
Using NvgSharp in MonoGame or FNA
Roman Shapiro edited this page Jun 22, 2022
·
16 revisions
There are two ways of referencing NvgSharp in the project:
-
Through nuget(works only for MonoGame and Stride):
-
As source code(works for all supported engines):
a. Clone this repo.
b. Add src/XNA/NvgSharp.{Engine}.csproj to the solution.
- If FNA is used, 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
};
}
## Context Creation
Add following field to the Game class:
```c#
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.BeginFrame(_graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight, 1.0f);
_context.FillColor(Color.Red);
_context.Circle(100, 100, 20);
_context.Fill();
_context.EndFrame();
https://github.com/rds1983/NvgSharp/tree/master/samples/NvgSharp.Samples.Demo