DotNetElements.DebugDraw.OpenTK
0.1.1
Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package DotNetElements.DebugDraw.OpenTK --version 0.1.1
NuGet\Install-Package DotNetElements.DebugDraw.OpenTK -Version 0.1.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotNetElements.DebugDraw.OpenTK" Version="0.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotNetElements.DebugDraw.OpenTK" Version="0.1.1" />
<PackageReference Include="DotNetElements.DebugDraw.OpenTK" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DotNetElements.DebugDraw.OpenTK --version 0.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DotNetElements.DebugDraw.OpenTK, 0.1.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DotNetElements.DebugDraw.OpenTK@0.1.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DotNetElements.DebugDraw.OpenTK&version=0.1.1
#tool nuget:?package=DotNetElements.DebugDraw.OpenTK&version=0.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DotNetElements.DebugDraw
A high-performance debug rendering library for .NET, providing an immediate-mode API for drawing debug primitives in OpenGL based 3D applications.
Features
- Immediate-mode debug drawing API
- Modern OpenGL GPU-driven instanced rendering with minimal CPU overhead
- No runtime allocations during rendering
- Support for common 3D debug primitives: boxes, spheres, lines, cylinders, cones, capsules, arrows, and grids (wireframe and solid)
- Custom mesh registration support
- Backend implementations for OpenTK and Silk.NET (easy to extend to other OpenGL bindings)
Requirements
- .NET 9.0 or later
- OpenTK 4.9.4+ or Silk.NET 2.22.0+ (depending on chosen backend)
- OpenGL 4.6 compatible GPU
Installation
Choose the backend that matches your application:
OpenTK Backend
dotnet package add DotNetElements.DebugRenderer.OpenTk
Silk.NET Backend
dotnet package add DotNetElements.DebugRenderer.Silk.Net
Quick Start
OpenTK Example
using DotNetElements.DebugRenderer.Core;
using DotNetElements.DebugRenderer.OpenTk;
using System.Numerics;
// Initialize the renderer (make sure you have a valid OpenGL context initialized first)
DebugDrawRenderer<OpenTkContext> debugDrawRenderer = new(new OpenTkContext());
// In your render loop
void OnRender()
{
debugDrawRenderer.BeginRender(viewProjectionMatrix);
// Draw primitives
DebugDraw.Box(new Vector3(0, 0, 0), Quaternion.Identity, 1f, 1f, 1f, DebugColor.Green);
DebugDraw.Line(Vector3.Zero, Vector3.UnitX, DebugColor.Red);
DebugDraw.Sphere(new Vector3(-1, 1, 3), 0.5f, DebugColor.Cyan, wireframe: false);
debugDrawRenderer.EndRender();
}
// Cleanup
debugDrawRenderer.Dispose();
Silk.NET Example
using DotNetElements.DebugRenderer.Core;
using DotNetElements.DebugRenderer.Silk.Net;
using System.Numerics;
// Initialize the renderer (glApi is your Silk.NET GL instance >>> needs to be initialized first)
DebugDrawRenderer<SilkNetContext> debugDrawRenderer = new(new SilkNetContext(glApi));
// In your render loop
void OnRender()
{
debugDrawRenderer.BeginRender(viewProjectionMatrix);
// Draw primitives
DebugDraw.Box(new Vector3(0, 0, 0), Quaternion.Identity, 1f, 1f, 1f, DebugColor.Green);
DebugDraw.Line(Vector3.Zero, Vector3.UnitX, DebugColor.Red);
DebugDraw.Sphere(new Vector3(-1, 1, 3), 0.5f, DebugColor.Cyan, wireframe: false);
debugDrawRenderer.EndRender();
}
// Cleanup
debugDrawRenderer.Dispose();
Available Primitives
- Box - Solid or wireframe boxes with rotation
- AxisAlignedBox - Axis-aligned bounding boxes
- Sphere - Solid or wireframe spheres
- Line - Single line between two points
- Cylinder - Cylinders with customizable orientation
- Cone - Cones pointing in any direction
- Capsule - Capsules (by default non accurate end-caps, use custom mesh registration for best results)
- Arrow - Directional arrows with customizable scale
- Grid - Grid meshes (need to be registered first)
- Origin - Common coordinate system axes indicator
Custom Meshes
To render custom meshes, you first need to register them with the DebugDraw.RegisterCustomMesh method (this can be only done during initialization).
Once registered, you can draw them using the DebugDraw.CustomMesh method.
void OnLoad()
{
DebugDrawRenderer<OpenTkContext> renderer = new(new OpenTkContext(), OnRegisterCustomMeshes);
}
void OnRegisterCustomMeshes()
{
// Register a grid mesh
DebugDraw.RegisterGridMesh(meshId: 1, width: 10f, height: 10f, spacing: 1f);
// Register other custom mesh
Vector3[] vertices = ...; // Your vertex data
uint[] indices = ...; // Your index data
DebugDraw.RegisterCustomMesh(meshId: 2, Topology.TriangleList, vertices, indices)
}
void OnRender()
{
// Draw the custom mesh
DebugDraw.Grid(meshId: 1, center: Vector3.Zero, GridPlane.XZ, DebugColor.White);
Matrix4x4 model = Matrix4x4.Identity;
DebugDraw.CustomMesh(meshId: 2, model, DebugColor.Yellow);
}
Examples
Complete examples are available in the examples folder:
- DotNetElements.DebugRenderer.Examples.OpenTk - Full OpenTK integration with camera controls
- DotNetElements.DebugRenderer.Examples.SilkNet - Full Silk.NET integration with camera controls
Compatibility
Tested on the following GPU drivers
- Intel(R) Iris(R) Xe Graphics OpenGL 4.6.0 - Build 32.0.101.6556
- NVIDEA GeForce RTX 3060 OpenGL 4.6.0 - Build 560.94
- AMD integrated ... // todo
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- DotNetElements.DebugDraw (>= 0.1.1)
- OpenTK.Graphics (>= 4.9.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.