ThoughtStuff.WebGLTemplate 1.5.0

There is a newer version of this package available.
See the version list below for details.
dotnet new install ThoughtStuff.WebGLTemplate::1.5.0                
This package contains a .NET Template Package you can call from the shell/command line.

.NET WebGL Template

A starting point for creating .NET projects that target WebAssembly and leverage WebGL
dotnet new webgl

Game Framework

This template includes a very basic GameFramework to help you get started. You only need to implement IGame and pass your Game instance to the GameController in Program.cs. See ExampleGame.cs for a simple example. See the Examples folder for more examples.

That said, you are not required to use the GameFramework. You can delete the GameFramework folder and implement your own rendering and update logic.

The IGame interface provides some "lifecycle" methods for you to implement for initialization, input, updates and rendering. These methods are called by the GameController at the appropriate times. See IGame.cs for documentation.

Invoking WebGL functions is straightforward via the global static GL class.

GL.ClearColor(0.39f, 0.58f, 0.93f, 1.0f);
GL.Clear(GL.COLOR_BUFFER_BIT);

Interop

The GL context is effectively exported by JS as follows:

const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
setModuleImports("main.js", { gl });

And imported in C# as in this example:

static partial class GL
{
    [JSImport("gl.clearColor", "main.js")]
    internal static partial void ClearColor(float red, float green, float blue, float alpha);
}

So this approach is limited to one Canvas context.

  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 119 9/17/2024
1.6.0 119 9/14/2024
1.5.0 108 9/8/2024
1.4.0 113 8/30/2024
1.3.0 109 8/30/2024
1.2.0 103 8/29/2024
1.1.0 111 8/29/2024
1.0.0 122 8/28/2024