A C# implementation of the core raylib API using Veldrid as the graphics backend. This project provides a familiar raylib-style interface for 2D graphics programming while leveraging Veldrid's modern, cross-platform graphics capabilities.
InitWindow(width, height, title)- Initialize graphics windowWindowShouldClose()- Check if window should closeCloseWindow()- Close window and cleanup resourcesSetTargetFPS(fps)- Set target frames per second
BeginDrawing()/EndDrawing()- Begin/end drawing frameClearBackground(color)- Clear screen with specified color
DrawRectangle(x, y, width, height, color)- Draw rectangleDrawRectangleRec(rectangle, color)- Draw rectangle from Rectangle structDrawCircle(centerX, centerY, radius, color)- Draw circleDrawCircleV(center, radius, color)- Draw circle from Vector2DrawLine(startX, startY, endX, endY, color)- Draw lineDrawLineV(startPos, endPos, color)- Draw line from Vector2sDrawPixel(x, y, color)- Draw single pixel
DrawText(text, x, y, fontSize, color)- Draw text (placeholder implementation)MeasureText(text, fontSize)- Measure text width
IsKeyPressed(key)- Check if key was just pressedIsKeyDown(key)- Check if key is currently held downIsKeyReleased(key)- Check if key was just releasedIsKeyUp(key)- Check if key is not pressedGetMousePosition()- Get current mouse position
GetScreenWidth()/GetScreenHeight()- Get screen dimensionsGetFrameTime()- Get time for last frameGetFPS()- Get current FPS
- Veldrid (4.9.0) - Modern graphics API abstraction
- Veldrid.StartupUtilities (4.9.0) - Window and graphics device creation helpers
- Veldrid.SDL2 (4.9.0) - SDL2 backend for windowing
- System.Numerics.Vectors (4.5.0) - Vector math support
dotnet restore
dotnet build
dotnet runusing VeldridRaylib;
// Initialize window
Raylib.InitWindow(800, 450, "My Game");
Raylib.SetTargetFPS(60);
// Main game loop
while (!Raylib.WindowShouldClose())
{
// Update game logic here
Raylib.BeginDrawing();
Raylib.ClearBackground(Color.DarkGray);
Raylib.DrawRectangle(100, 100, 200, 150, Color.Red);
Raylib.DrawCircle(400, 200, 50, Color.Blue);
Raylib.DrawText("Hello World!", 10, 10, 20, Color.White);
Raylib.EndDrawing();
}
Raylib.CloseWindow();The implementation consists of several key components:
- Raylib.cs - Main API interface matching raylib's function signatures
- Renderer.cs - Core 2D renderer using Veldrid's graphics pipeline
- Shader.cs - Basic vertex/fragment shaders for 2D rendering
- Color.cs - Color structure with predefined colors
- Vector2.cs - 2D vector and rectangle structures
- Text rendering is placeholder (no actual font rendering)
- Mouse button input is not fully implemented
- No texture/image loading support
- No audio support
- Limited to basic 2D shapes and primitives
- Full text rendering with font support
- Texture and sprite rendering
- Audio system integration
- More advanced shape drawing (polygons, bezier curves)
- Performance optimizations
- Additional input handling features