Programming Setup

Installation

  1. Install the .NET 7 SDK.
  2. Install VisualStudio (Windows only) or the VS Code development environment and setup a C# project. You can test the development setup by creating a new folder and open a terminal in that folder with the console commands: dotnet new console dotnet restore dotnet build dotnet run code .
  3. In the C# project, install the SharpGfx.OpenGL.OpenTK nuget package into your project via the package manager. Alternatively you can use the cosole command: dotnet add package SharpGfx.OpenGL.OpenTK
  4. Rebuild your project.

SharpGfx Test Program

The following code demonstrates a complete hello triangle program producing a plain triange that can be viewed in 3D. This code serves as function test. Also, you get an idea how it looks like.
// It is sufficient to reference package SharpGfx.OpenTK, the other needed packages will be included automatically using System; using SharpGfx; using SharpGfx.Cameras; using SharpGfx.Coordinates; using SharpGfx.Geometries; using SharpGfx.Lighting; using SharpGfx.OpenGL.OpenTK; public class TriangleRendering : Rendering { public TriangleRendering(Graphic graphic) : base(graphic, new Color3(0.2f, 0, 0.2f)) { } public override void OnLoad() { float[] vertices = { -0.5f,-0.5f, 0, 0.5f,-0.5f, 0, 0.0f, 0.5f, 0 }; float[] normals = { 0, 0, 1, 0, 0, 1, 0, 0, 1 }; var material = new Material[] { new EmissiveUniformMaterial(new Color4(1, 0, 0, 0)) }; var shading = Graphic.CreateShading(Array.Empty<Light>(), material); var geometry = new NormalGeometry(vertices, normals); var surface = Graphic.CreateSurface(shading, geometry); var triangle = Graphic.CreateVisual("", surface); Scene.Add(triangle); } } static class Program { static void Main() { var graphic = new OpenTkGraphic(); var camera = new OrbitCamera(Space.Origin3, 2, Space.Unit3Z); using var rendering = new TriangleRendering(graphic); var window = new OpenTkWindow("Demo", 1024, 640); window.Show(rendering, camera); } }