NotNotTech / Raylib-CsLo

autogen bindings to Raylib 4.x and convenience wrappers on top. Requires use of `unsafe`
Mozilla Public License 2.0
117 stars 10 forks source link
csharp game-development gamedev pinvoke raylib raylib-cslo
Raylib-CsLo-Logo

Nuget Package Source Code Source Code .NET 5+ Chat on Discord

Table of Contents

Mac M1 is now supported

v4.2.0.5 should now include full osx support, both x64 and arm64, which includes supporting the M1.
If you test on the M1 and have problems, please raise an issue.

About

Managed C# bindings to Raylib, a friendly 2d/3d game framework similar to XNA / MonoGame.

What is Raylib?

Raylib is a friendly-to-use game framework that includes basic scenarios to meet your needs: audio, 2d, 3d, fonts, animation, 2d physics. Somewhat similar to Xna or MonoGame but friendlier. However, Raylib is a C/CPP framework. Raylib-CsLo is a C# Wrapper over the top, which lets you gain raylib's powers to quickly prototype your game ideas.

Super easy to use for 2d

If you stick with 2d, you don't need to use any unsafe (pointer) code, which lets 2d users feel at home and use Raylib-CsLo as an awesome 2d game framework.

High performance for 3d! (but unsafe to use)

3d in CsLo requires the unsafe keyword. If you use 3d, you need to understand a bit of how pointers work. Raylib uses these to link things like Model, Mesh, and Material. Writing wrappers over these is possible but it would basically be creating a an entirely new framework. I suggest leaving this as-is, as it avoids object allocation (GC Pressure).

Additionally, 3d users: Be sure you check the Usage Tips section below, especially on how you need to use Matrix4x4.Transpose() when sending matricies to Raylib.

How to use/install

via Nuget

  1. add the latest version of The Raylib-CsLo Nuget Package to your project
  2. Create an example project using it, the following code is coppied from The StandAlone Example's Program.cs
using Raylib_CsLo;

namespace StandaloneExample
{
 public static class Program
 {
  public static async Task Main(string[] args)
  {
   Raylib.InitWindow(1280, 720, "Hello, Raylib-CsLo");
   Raylib.SetTargetFPS(60);
   // Main game loop
   while (!Raylib.WindowShouldClose()) // Detect window close button or ESC key
   {
    Raylib.BeginDrawing();
    Raylib.ClearBackground(Raylib.SKYBLUE);
    Raylib.DrawFPS(10, 10);
    Raylib.DrawText("Raylib is easy!!!", 640 , 360, 50, Raylib.RED);
    Raylib.EndDrawing();
   }
   Raylib.CloseWindow();
  }
 }
}

via sources

  1. clone/download the github repository
  2. open ./Raylib-CsLo-DEV.sln in Visual Studio 2022.
  3. build and run.
    • the Raylib-CsLo.Examples project will run by default, and will run through all (aprox 100+) examples.
  4. For a stand-alone example that uses the Nuget Package, see the ./StandaloneExample folder

Linux / OsX / other platform support

The following platforms are shipped in the nuget package:

You can build the native binaries for whatever platform you need. Please see the readme under https://github.com/NotNotTech/Raylib-CsLo/tree/main/Raylib-CsLo/runtimes for more info.

Examples

Here are links to most the examples.

Core Shapes Textures Text Models Shaders Audio Physics
Ex1 Ex1 Ex1 Ex1 Ex1 Ex1 Ex1 Ex1
Ex2 Ex2 Ex2 Ex2 Ex2

Differences from Raylib-Cs

Raylib-Cs Raylib-CsLo
An artisanal, bespoke binding+wrapper. A cold, calculating robo-binding.
Each binding is hand crafted with carefull design Exact Bindings (Autogen) with wrappers to make C# usage nice.
Bindings for Raylib and extras RayMath, RlGl. Bindings for Raylib and all extras (RayGui, Easings, Physac, RlGl, RayMath)
Optimized for normal C# usage Optimized for maximum performance and might require unsafe
New Raylib version? Harder to detect breaking changes New Raylib version? Breaking changes are easy to spot and fix
includes Intellisence docs No docs. Use the Cheatsheet / Examples
Born 2018-07 Born 2021-11
Lots of examples ALL 100+ Raylib examples
zlib Licensed MPL 2.0 Licensed
Nuget Package Nuget Package
Raylib 4.0 Raylib 4.2
lots of contribs few contribs

Extras (1st person, 3rd person cameras)

If you need a custom camera, check out the Raylib-Extras-CsLo project, which contains a custom First Person Camera and Third Person Camera. https://github.com/NotNotTech/Raylib-Extras-CsLo

Usage Tips, FAQ

Known Issues

TROUBLESHOOTING your game

Frame stutters, hitching, spikes

How to Contribute

0) assume you are using Visual Studio (or maybe rider?) and can run dev.sln 1) fork the repo, build and try out the example project 2) Pick something to do

Want to build from scratch?

check out the readme under the binding-gen folder

yoink the native binary instead

If there is a platform that doesn't work due to no native binary being shipped with the Raylib-CsLo nuget package, you should just be able to yoink the official raylib native library ...like from here and if it's put in the right folder location (output folder), raylib-cslo can use it, assuming it's named properly. If you do this you need to be aware that the various raylib-extras will not be available, but everything else should work.

License options: MPL or PCL

Mozilla Public License 2_0 (MPL)

By default, this repository is licensed under the Mozilla Public License 2.0 (MPL). The MPL is a popular "weak copyleft" license that allows just about anything. For example, you may use/include/static-link this library in a commercial, closed-source project without any burdens. The main limitation of the MPL being that: Modifications to the source code in this project must be open sourced.

The MPL is a great choice, both by providing flexibility to the user, and by encouraging contributions to the underlying project. If you would like to read about the MPL, FOSSA has a great overview of the MPL 2.0 here.

Private Commercial License (PCL)

If for some reason you or your organization really, REALLY can not open source your modifications to this project, I am willing to offer a PCL for USD $1000, half of which will be donated to the upstream raylib project. Payment can be made via github donations. Yes $1000 is a lot of money, so just try to accept the MPL terms and move on with life! If you still think a PCL is what you need, raise an issue or email JasonS aat Novaleaf doot coom to discuss.

ChangeLog

changelog for major releases.