A C# implementation of core Raylib functions using Silk.NET OpenGL bindings. SilkRay provides a Raylib-compatible 2D graphics API for cross-platform game development and graphics programming.
SilkRay provides a familiar Raylib-style API for 2D graphics programming in C# using modern Silk.NET libraries. It implements core 2D functionality including window management, shape drawing, input handling, camera system, and text rendering with full NativeAOT support.
- Window management (
InitWindow,CloseWindow,WindowShouldClose) - Drawing lifecycle (
BeginDrawing,EndDrawing,ClearBackground) - Screen properties (
GetScreenWidth,GetScreenHeight) - Timing functions (
GetTime,GetFrameTime,GetFPS) - Monitor information (
GetMonitorWidth,GetMonitorHeight,GetMonitorName)
- Keyboard:
IsKeyDown,IsKeyPressed,IsKeyReleased,GetKeyPressed,GetCharPressed - Mouse:
IsMouseButtonDown,IsMouseButtonPressed,IsMouseButtonReleased,GetMousePosition,GetMouseWheelMove - Gamepad:
IsGamepadAvailable,IsGamepadButtonDown,GetGamepadAxisMovement - Cursor:
ShowCursor,HideCursor,SetMouseCursor
- Pixels:
DrawPixel,DrawPixelV - Lines:
DrawLine,DrawLineV,DrawLineEx - Rectangles:
DrawRectangle,DrawRectangleV,DrawRectangleRec,DrawRectangleLines,DrawRectanglePro - Circles:
DrawCircle,DrawCircleV,DrawCircleLines - Triangles:
DrawTriangle
- Camera2D: Complete camera with target, offset, rotation, and zoom
- Coordinate conversion:
GetScreenToWorld2D,GetWorldToScreen2D - Camera matrix:
BeginMode2D,EndMode2D
- Text drawing:
DrawText,DrawTextEx - Font loading:
LoadFont,UnloadFont - Text measurement:
MeasureText,MeasureTextEx
- File operations:
FileExists,DirectoryExists,GetFileLength,GetFileModTime - Path utilities:
GetFileExtension,GetFileName,GetFileNameWithoutExt,GetDirectoryPath - Extension checking:
IsFileExtension
Color- RGBA color with predefined constants (UPPERCASE naming)Vector2- 2D vector math operationsRectangle- Rectangle structure for boundsCamera2D- 2D camera with transformation matrix
using static SilkRay.Core;
using static SilkRay.Shapes;
using static SilkRay.Text;
// Initialize 2D window
InitWindow(800, 450, "My SilkRay App");
SetTargetFPS(60);
// Main loop
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(RAYWHITE);
// Draw 2D shapes
DrawRectangle(100, 100, 200, 100, RED);
DrawCircle(400, 200, 50, BLUE);
DrawLine(0, 0, 800, 450, GREEN);
DrawText("Hello SilkRay 2D!", 10, 10, 20, BLACK);
EndDrawing();
}
CloseWindow();dotnet add package SilkRaygit clone https://github.com/AliasBLACK/SilkRay.git
cd SilkRay
dotnet buildComprehensive example projects are available in a separate repository:
Repository: https://github.com/AliasBLACK/SilkRayExamples
- BasicShapes - Core 2D shape drawing and animation
- MouseInput - Complete mouse input handling with trails and cursors
- GamepadInput - Gamepad support with analog sticks and buttons
- Camera2D - 2D camera system with zoom, rotation, and following
All examples support NativeAOT compilation for optimal 2D performance.
dotnet restore
dotnet builddotnet publish -c Release -r win-x64 --self-contained- Silk.NET.OpenGL (2.22.0)
- Silk.NET.Windowing (2.22.0)
- Silk.NET.Input (2.22.0)
- Silk.NET.Windowing.Glfw (2.22.0)
- Silk.NET.Input.Glfw (2.22.0)
- FontStashSharp (for text rendering)
- TextCopy (for clipboard operations)
- StbImageSharp (for image loading)
- .NET 8.0
- NativeAOT Compatible: Zero-cost abstractions with ahead-of-time compilation
- 2D Optimized: Efficient batch rendering for shapes and sprites
- Memory Efficient: Minimal allocations in 2D rendering hot paths
- Cross-platform: Uses OpenGL for consistent 2D performance across platforms