Skip to content

Commit

Permalink
Added basic test project
Browse files Browse the repository at this point in the history
  • Loading branch information
Visual-Vincent committed Jan 10, 2022
1 parent 1d8e34d commit 90ab5cd
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Generator/Generator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</ItemGroup>

<ItemGroup>
<None Update="Licenses\CommandLineParser.txt">
<None Update="Licenses\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
16 changes: 15 additions & 1 deletion NanoVG.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NanoVG.Native", "NanoVG.Nat
{363756D7-CA1B-4870-AD45-A2AAD3A6A9FB} = {363756D7-CA1B-4870-AD45-A2AAD3A6A9FB}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Generator", "Generator\Generator.csproj", "{363756D7-CA1B-4870-AD45-A2AAD3A6A9FB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Generator", "Generator\Generator.csproj", "{363756D7-CA1B-4870-AD45-A2AAD3A6A9FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{90C6EC8D-BF79-4D14-A069-6C198817D636}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -60,6 +62,18 @@ Global
{363756D7-CA1B-4870-AD45-A2AAD3A6A9FB}.Release|x64.Build.0 = Release|Any CPU
{363756D7-CA1B-4870-AD45-A2AAD3A6A9FB}.Release|x86.ActiveCfg = Release|Any CPU
{363756D7-CA1B-4870-AD45-A2AAD3A6A9FB}.Release|x86.Build.0 = Release|Any CPU
{90C6EC8D-BF79-4D14-A069-6C198817D636}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90C6EC8D-BF79-4D14-A069-6C198817D636}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90C6EC8D-BF79-4D14-A069-6C198817D636}.Debug|x64.ActiveCfg = Debug|Any CPU
{90C6EC8D-BF79-4D14-A069-6C198817D636}.Debug|x64.Build.0 = Debug|Any CPU
{90C6EC8D-BF79-4D14-A069-6C198817D636}.Debug|x86.ActiveCfg = Debug|Any CPU
{90C6EC8D-BF79-4D14-A069-6C198817D636}.Debug|x86.Build.0 = Debug|Any CPU
{90C6EC8D-BF79-4D14-A069-6C198817D636}.Release|Any CPU.ActiveCfg = Release|x86
{90C6EC8D-BF79-4D14-A069-6C198817D636}.Release|Any CPU.Build.0 = Release|x86
{90C6EC8D-BF79-4D14-A069-6C198817D636}.Release|x64.ActiveCfg = Release|x86
{90C6EC8D-BF79-4D14-A069-6C198817D636}.Release|x64.Build.0 = Release|x86
{90C6EC8D-BF79-4D14-A069-6C198817D636}.Release|x86.ActiveCfg = Release|x86
{90C6EC8D-BF79-4D14-A069-6C198817D636}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
7 changes: 7 additions & 0 deletions NanoVG.NET/NVG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@ public struct NVGcolor
{
public float r,g,b,a;
}

public enum NVGcreateFlags
{
NVG_ANTIALIAS = 1<<0,
NVG_STENCIL_STROKES = 1<<1,
NVG_DEBUG = 1<<2,
}
}
3 changes: 3 additions & 0 deletions NanoVG.NET/NVG.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -849,5 +849,8 @@ public static unsafe partial class NVG
[DllImport(LibraryName, EntryPoint = FunctionPrefix + nameof(lImageHandleGL3))]
public static extern uint lImageHandleGL3(this NVGcontext ctx, int image);

[DllImport(LibraryName, EntryPoint = FunctionPrefix + nameof(CreateGL3Context))]
public static extern NVGcontext CreateGL3Context(int flags);

}
}
2 changes: 1 addition & 1 deletion NanoVG.NET/NanoVG.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="&quot;$(SolutionDir)Generator\bin\$(ConfigurationName)\netcoreapp3.1\Generator.exe&quot; extract-text -f &quot;$(SolutionDir)nanovg\src\nanovg_gl.h&quot; -s &quot;#if defined NANOVG_GL3&quot; -e &quot;#endif&quot; -c 1 -i -o &quot;$(ProjectDir)obj\nanovg_gl.h&quot;&#xD;&#xA;&quot;$(SolutionDir)Generator\bin\$(ConfigurationName)\netcoreapp3.1\Generator.exe&quot; pinvoke -l NanoVG -n NanoVG -c NVG -f &quot;$(SolutionDir)nanovg\src\nanovg.h&quot; &quot;$(ProjectDir)obj\nanovg_gl.h&quot; -o &quot;$(ProjectDir)NVG.g.cs&quot; --funcprefix nvg --partial-class" />
<Exec Command="&quot;$(SolutionDir)Generator\bin\$(ConfigurationName)\netcoreapp3.1\Generator.exe&quot; extract-text -f &quot;$(SolutionDir)nanovg\src\nanovg_gl.h&quot; -s &quot;#if defined NANOVG_GL3&quot; -e &quot;#endif&quot; -c 1 -i -o &quot;$(ProjectDir)obj\nanovg_gl.h&quot;&#xD;&#xA;&quot;$(SolutionDir)Generator\bin\$(ConfigurationName)\netcoreapp3.1\Generator.exe&quot; pinvoke -l NanoVG -n NanoVG -c NVG -f &quot;$(SolutionDir)nanovg\src\nanovg.h&quot; &quot;$(ProjectDir)obj\nanovg_gl.h&quot; &quot;$(SolutionDir)NanoVG.Native\nanovg_bridge.c&quot; -o &quot;$(ProjectDir)NVG.g.cs&quot; --funcprefix nvg --partial-class" />
</Target>

</Project>
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# NanoVG.NET
.NET Core bindings for [NanoVG](https://github.com/memononen/nanovg).

Inspired by [Saša Barišić's NanoVG port](https://github.com/sbarisic/nanovg_dotnet) for .NET Framework. Remade from scratch to build a more automated workflow, making it easier to stay up-to-date with NanoVG.

## System requirements
- .NET Core 3.1 or newer

Windows-specific requirements:
- Windows 7 SP1 or newer
- Microsoft Visual C++ 2019 Redistributable (x86, x64 or both, depending on which platform(s) you target)
- https://docs.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist
4 changes: 4 additions & 0 deletions Test/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[assembly: System.Reflection.AssemblyTitle("NanoVG.NET Test")]
[assembly: System.Reflection.AssemblyProduct("NanoVG.NET Test")]
[assembly: System.Reflection.AssemblyCopyright("Copyright © Visual Vincent 2022")]
[assembly: System.Reflection.AssemblyVersion("1.0.0.0")]
23 changes: 23 additions & 0 deletions Test/Licenses/OpenTK.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
MIT License

Copyright (c) 2006-2020 Stefanos Apostolopoulos for the Open Toolkit project.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Third party licenses may be applicable. These have been disclosed in OpenTK_THIRD_PARTIES.md
14 changes: 14 additions & 0 deletions Test/Licenses/OpenTK_THIRD_PARTIES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Third parties

## OpenEXR

> OpenTK.Half offers Half-to-Single and Single-to-Half conversions based on OpenEXR source code, which is covered by the following license:
Copyright (c) 2002, Industrial Light & Magic, a division of Lucas Digital Ltd. LLC. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Industrial Light & Magic nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 changes: 31 additions & 0 deletions Test/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Runtime.InteropServices;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;

namespace NanoVG.Test
{
class Program
{
static void Main(string[] args)
{
var nativeWindowSettings = new NativeWindowSettings() {
APIVersion = new Version(3, 3),
Size = new Vector2i(800, 600),
Title = "NanoVG.NET Test",
NumberOfSamples = 8, // 8x MSAA,
Flags = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? ContextFlags.ForwardCompatible : ContextFlags.Default
};

var gameWindowSettings = new GameWindowSettings();

using(var window = new TestWindow(gameWindowSettings, nativeWindowSettings))
{
window.CenterWindow();
window.VSync = VSyncMode.On;
window.Run();
}
}
}
}
32 changes: 32 additions & 0 deletions Test/Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AssemblyName>NanoVG.Test</AssemblyName>
<RootNamespace>NanoVG.Test</RootNamespace>
<Platforms>x86</Platforms>
</PropertyGroup>

<ItemGroup>
<None Include="..\NanoVG.Native\Win32\Release\NanoVG.dll" Link="NanoVG.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="OpenTK" Version="4.6.7" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NanoVG.NET\NanoVG.NET.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="Licenses\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
55 changes: 55 additions & 0 deletions Test/TestWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using OpenTK.Graphics.OpenGL;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;

namespace NanoVG.Test
{
class TestWindow : GameWindow
{
public TestWindow(GameWindowSettings gameWindowSettings, NativeWindowSettings nativeWindowSettings)
: base(gameWindowSettings, nativeWindowSettings)
{
}

NVGcontext ctx;

protected override void OnLoad()
{
base.OnLoad();
ctx = NVG.CreateGL3Context((int)(NVGcreateFlags.NVG_STENCIL_STROKES | NVGcreateFlags.NVG_ANTIALIAS));
}

protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);

GL.ClearColor(Color4.Black);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);

ctx.BeginFrame(ClientSize.X, ClientSize.Y, 96.0f);
OnRenderUI(ctx);
ctx.EndFrame();

SwapBuffers();
}

protected virtual void OnRenderUI(NVGcontext ctx)
{
ctx.BeginPath();

ctx.RoundedRect(8, 8, 300, 300, 16);
ctx.FillColor(new NVGcolor() { r = 255, g = 0, b = 0, a = 255 });
ctx.Fill();

ctx.Restore();
}

protected override void OnResize(ResizeEventArgs e)
{
base.OnResize(e);
GL.Viewport(0, 0, e.Width, e.Height);
}
}
}

0 comments on commit 90ab5cd

Please sign in to comment.