SDL3-CS C# Bindings

repository·main·Indexed 42 days ago

https://github.com/edwardgushchin/sdl3-cs

Modern C# bindings and native NuGet packages for SDL3 and its companion libraries, including SDL_image, SDL_ttf, SDL_mixer, and SDL_shadercross. It enables cross-platform .NET applications with predictable native runtime distribution across Windows, Linux, MacOS, Android, iOS, and tvOS. Features include managed main callback lifecycles via [SDL.GenerateMain], Android-specific hosting through SDLActivity, and support for asynchronous I/O and audio streaming.

Tokens
35.2K
Snippets
129
Records
260
Agent score
51%

What's inside SDL3-CS

  1. Overview of Renderer Primitives demonstration

    main

    The Renderer Primitives example demonstrates the fundamental drawing capabilities of the SDL renderer. It serves as a foundation for more specialized renderer samples by showcasing:

    • Drawing basic geometric primitives: points, lines, and rectangles.
    • Color management: Using colors and alpha (transparency) in a scene.
    • Frame lifecycle: Presenting renderer output to the screen each frame.
  2. Understand the Demo Snake project model

    main

    Demo Snake is a port of the classic SDL sample game to SDL3-CS. It demonstrates several core game development patterns using the SDL3-CS bindings:

    • Game Loop Implementation: Using SDL events to drive the loop.
    • Timing Separation: Decoupling update logic (game state) from rendering logic.
    • Input Handling: Using keyboard input for character movement.
    • Rendering: Drawing grid-based scenes using SDL renderer APIs.

    Technical Specifications:

    • Target Framework: net10.0
    • Language Version: C# 14
    • Runtime Dependency: Requires the base SDL3-CS.<Platform> native runtime package.
    • Assets: No external project-specific assets are required.
  3. Demonstrated SDL_image capabilities in Color Quantization

    main

    The Color Quantization example serves as a demonstration of how to integrate and use the SDL_image native package via SDL3-CS. It covers the following workflow:

    1. Loading Image Data: Using SDL3-CS image bindings to load image files.
    2. Image Processing: Applying color quantization operations to the loaded data.
    3. Output: Displaying or saving the results using SDL surfaces or renderer textures.
  4. Understand the Camera example functionality

    main

    The Camera example demonstrates how to interact with camera hardware using managed C# code via SDL3-CS. It covers the following lifecycle steps:

    1. Subsystem Initialization: Initializing the SDL camera subsystem.
    2. Enumeration: Listing all available camera devices on the host.
    3. Device Access: Opening a selected camera device safely.
    4. Cleanup: Reporting device availability and handling shutdown results.
  5. Understand the Pen Drawing Lines demonstration

    main

    The Pen Drawing Lines project is an example of how to handle advanced pointer input using SDL3-CS. It demonstrates the following capabilities:

    • Receiving SDL pen events: Capturing specific input events generated by pen/tablet hardware.
    • Tracking pen coordinates and pressure: Accessing precise positional data and pressure-sensitive input where the hardware supports it.
    • Drawing input paths: Using renderer primitives to draw the strokes created by the pen.
    • Fallback handling: Managing pointer devices that do not provide specialized pen data (treating them as standard pointers).
  6. Demonstrated Renderer Geometry capabilities

    main

    The Renderer Geometry example showcases how to use SDL renderer APIs for advanced graphics beyond simple rectangles and textures. Specifically, it demonstrates:

    • Building vertex data: Creating vertex structures directly from managed C# code.
    • Submitting colored geometry: Passing custom geometry data to the renderer.
    • Animation: Animating custom triangles or quads within the SDL window.
  7. Understand the Input Gamepad Events demonstration

    main

    The Input Gamepad Events project demonstrates how to handle event-driven gamepad input using SDL3-CS. Key capabilities include:

    • Listening for events: Detecting gamepad connection and button press/release events.
    • Opening gamepads: Accessing gamepads reported by the SDL subsystem.
    • Event Mapping: Mapping SDL event payloads into managed C# logging.
    • Lifecycle Management: Handling hot-plug (connecting/disconnecting) and quit events within a single event loop.
  8. Understand the Misc Clipboard example capabilities

    main

    The Misc Clipboard example serves as a demonstration of the following SDL3-CS features:

    • Clipboard Operations: Reading and writing text content to the system clipboard.
    • Error Handling: Checking SDL success and error paths.
    • Utility Pattern: Using a small, utility-style SDL program that operates without a rendering context.
    • Platform Abstraction: Using SDL APIs to keep platform-specific clipboard differences hidden from the application logic.
  9. Understand the Asyncio Load Bitmaps project model

    main

    The Asyncio Load Bitmaps example demonstrates how to integrate SDL asynchronous I/O with image loading in a renderer sample. Key capabilities include:

    • Non-blocking I/O: Scheduling file reads without blocking the main execution loop.
    • Async State Tracking: Monitoring asynchronous completion state within a standard SDL event loop.
    • Asset Integration: Converting loaded bitmap data into content visible to the SDL renderer.
    • Responsiveness: Maintaining window responsiveness while assets are being loaded in the background.

    Requirements:

    • .NET 10 SDK.
    • A platform supported by SDL3-CS native packages (Windows, Linux, or macOS for desktop).
    • The base SDL3-CS.<Platform> native runtime package.
  10. Understand the Renderer Affine Textures project model

    main

    The Renderer Affine Textures project is a demonstration of affine texture rendering using SDL renderer APIs. It showcases the following capabilities:

    • Creating reusable sample textures.
    • Rendering texture corners through affine transforms.
    • Animating texture placement on a per-frame basis.
    • Utilizing the shared SDL3-CS example runner.

    Technical Specifications:

    • Runtime: .NET 10.0
    • Language: C# 14
    • Dependencies: Requires the base SDL3-CS.<Platform> native runtime package.
    • Build Configuration: Uses shared MSBuild targets (Directory.Build.props and Directory.Build.targets) which ensure desktop examples receive the matching native runtime package for Windows, Linux, or macOS.
  11. Understand the Renderer Read Pixels demonstration

    main

    The 'Renderer Read Pixels' example is designed to demonstrate how to interact with the SDL3 renderer to retrieve pixel data. It covers the following key tasks:

    • Standard Rendering: Performing normal frame rendering cycles.
    • Pixel Readback: Invoking SDL pixel readback APIs to capture the output.
    • Managed Data Handling: Managing and processing the pixel data returned from the native layer into managed C# code.
    • Performance Awareness: Understanding the performance implications (cost) and the data structure (shape) of different readback paths.