Watch
3
0
Fork
You've already forked raylib-cs
0
* Fix formatting/update doc comments in Raylib.cs

* Update types in Raylib.cs to 4.0

* Remove app.config

* Update Raylib.cs functions

* Split Enums, Structs & Classes into own files

* Testing utils for Raylib.cs

* Update Raylib-cs.csproj

* Reorganize types
- Move into types folder
- Group types based on usage

* Fix parameter names

* Rename CloseAudioStream to UnloadAudioStream

* Remove ref SetShaderValue overloads

* Remove some constants from Raylib.cs

* Include README.md in package

* Replace old version of GetDroppedUtils

* Update README.md

* Remove Physac-cs and Raygui-cs
- Not actively maintained and a pain for users to setup...

* Update comments to xmldoc

* Rename Gestures enum to Gesture

* Minor fixes
- Rename Gestures enum to Gesture
- Update tests to net6.0

* Testing CBool type instead of bool

* Update XmlDoc comments

* Update build.yml to net6.0 for tests

* Remove Easings.cs
- Easings used to be part of raylib. It is now a separate extra library
so I am removing it from the main bindings.

* Update rlgl

* More XmlDoc comments

* Use CBool in structs

* Big unsafe update

* Fix typos and change refs to pointers in Rlgl

* Update LoggingUtils and Material

* Fix typo in Rlgl

* Update build.yml

* Rename RaylibUtils.cs to Raylib.Utils
now a partial class

* Convert some RLGL consts to Enums

Also added helper methods/overloads for related methods

* Make class Raylib partial

* Convert some text functions to not use ref

I dont think they will work. need testing

* Testing fixes for Text functions

* Create rlMultMatrixf safe overload

* Implement safe ModelAnimation

* Testing fix for ModelAnimation using wrapper struct

* Added TODOs

* Fix rlMultMatrixf
- Add missing ToFloatV functions to Raymath
- Fix rlMultMatrixf overload to use MatrixToFloatV

* Fix IsGestureDetected and formatting

* Add a few text tests

* Move wrapper functions into Raylib.Utils

* Remove ref from raylib bindings

* Multi-target net5.0

* Testing string approaches

* Fixing more util and unsafe functions

* Testing TraceLogCallback fix

Set lang version to C# 10

* Replace managed callbacks with unsafe delegates

* Update default LogConsole callback

* Setup unsafe/safe functions for math types in Raylib.cs

* Replace string in Rlgl with sbyte*

* Yet more string changes
- Use sbyte/byte correctly in Raylib.cs
- Using Marshal.StringToCoTaskMemUTF8
- Update utils string usage

* Fix typo bug and whitespace

* Fix DrawTextPro and more whitespace

* Remove unused ToString

* Add file functions back into Raylib

* Test paths filter for pull requests

* Change to paths-ignore filter

* Redo partial change

* Move binding functions into interop folder

Co-authored-by: Ben Parsons <9parsonsb@gmail.com>
This commit is contained in:
Chris 2022-02-14 12:53:44 +00:00 • committed by Ben Parsons
commit e5934b86ba
38 changed files with 4422 additions and 3404 deletions

View file

@ -4,6 +4,9 @@ on:
branches: master branches: master
pull_request: pull_request:
branches: '*' branches: '*'
paths-ignore:
- 'README.md'
- '.github/ISSUE_TEMPLATE/**'
workflow_dispatch: workflow_dispatch:
jobs: jobs:
@ -18,16 +21,21 @@ jobs:
- name: Setup dotnet - name: Setup dotnet
uses: actions/setup-dotnet@v1 uses: actions/setup-dotnet@v1
with: with:
dotnet-version: 5.0.x dotnet-version: 6.0.x
- name: Build project - name: Build project
run: dotnet build -c Release run: dotnet build -c Release -f net6.0
- name: Test project - name: Test project
run: dotnet test run: dotnet test -c Release -f net6.0
publish: publish:
name: Build Release Package name: Build Release Package
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: build needs: build
steps: steps:
- uses: actions/checkout@v2
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Download Repo - name: Download Repo
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -41,12 +49,12 @@ jobs:
- name: echo tag - name: echo tag
run: echo ${{ steps.get-tag.outputs.info }} run: echo ${{ steps.get-tag.outputs.info }}
- name: Download raylib Release - name: Download win-x64 Raylib Release
uses: robinraju/release-downloader@v1.2 uses: robinraju/release-downloader@v1.3
with: with:
repository: "raysan5/raylib" repository: "raysan5/raylib"
tag: ${{ steps.get-tag.outputs.info }} tag: ${{ steps.get-tag.outputs.info }}
fileName: "*" fileName: "raylib-${{steps.get-tag.outputs.info}}_win64_msvc16.zip"
- name: extract win-x64 - name: extract win-x64
uses: montudor/action-zip@v1 uses: montudor/action-zip@v1
@ -59,6 +67,13 @@ jobs:
source: "raylib-win64/raylib-${{steps.get-tag.outputs.info}}_win64_msvc16/lib/raylib.dll" source: "raylib-win64/raylib-${{steps.get-tag.outputs.info}}_win64_msvc16/lib/raylib.dll"
target: "Raylib-cs/runtimes/win-x64/native/raylib.dll" target: "Raylib-cs/runtimes/win-x64/native/raylib.dll"
- name: Download win-x86 Raylib Release
uses: robinraju/release-downloader@v1.3
with:
repository: "raysan5/raylib"
tag: ${{ steps.get-tag.outputs.info }}
fileName: "raylib-${{steps.get-tag.outputs.info}}_win32_msvc16.zip"
- name: extract win-x86 - name: extract win-x86
uses: montudor/action-zip@v1 uses: montudor/action-zip@v1
with: with:
@ -70,6 +85,13 @@ jobs:
source: "raylib-win86/raylib-${{steps.get-tag.outputs.info}}_win32_msvc16/lib/raylib.dll" source: "raylib-win86/raylib-${{steps.get-tag.outputs.info}}_win32_msvc16/lib/raylib.dll"
target: "Raylib-cs/runtimes/win-x86/native/raylib.dll" target: "Raylib-cs/runtimes/win-x86/native/raylib.dll"
- name: Download linux-x64 Raylib Release
uses: robinraju/release-downloader@v1.3
with:
repository: "raysan5/raylib"
tag: ${{ steps.get-tag.outputs.info }}
fileName: "raylib-${{steps.get-tag.outputs.info}}_linux_amd64.tar.gz"
- name: extract linux-x64 - name: extract linux-x64
run: mkdir -p raylib-linux64 && tar -xvf raylib-${{steps.get-tag.outputs.info}}_linux_amd64.tar.gz -C raylib-linux64 run: mkdir -p raylib-linux64 && tar -xvf raylib-${{steps.get-tag.outputs.info}}_linux_amd64.tar.gz -C raylib-linux64
@ -79,6 +101,13 @@ jobs:
source: "raylib-linux64/raylib-${{steps.get-tag.outputs.info}}_linux_amd64/lib/libraylib.so.${{steps.get-tag.outputs.info}}" source: "raylib-linux64/raylib-${{steps.get-tag.outputs.info}}_linux_amd64/lib/libraylib.so.${{steps.get-tag.outputs.info}}"
target: "Raylib-cs/runtimes/linux-x64/native/libraylib.so" target: "Raylib-cs/runtimes/linux-x64/native/libraylib.so"
- name: Download osx-x64 Raylib Release
uses: robinraju/release-downloader@v1.3
with:
repository: "raysan5/raylib"
tag: ${{ steps.get-tag.outputs.info }}
fileName: "raylib-${{steps.get-tag.outputs.info}}_macos.tar.gz"
- name: extract osx-x64 - name: extract osx-x64
run: mkdir -p raylib-osx64 && tar -xvf raylib-${{steps.get-tag.outputs.info}}_macos.tar.gz -C raylib-osx64 run: mkdir -p raylib-osx64 && tar -xvf raylib-${{steps.get-tag.outputs.info}}_macos.tar.gz -C raylib-osx64
@ -96,7 +125,7 @@ jobs:
xpath: "//PackageVersion" xpath: "//PackageVersion"
- name: Create NuGet Package - name: Create NuGet Package
run: dotnet pack -c Release run: dotnet pack -c Release Raylib-cs
- name: Upload NuGet Package As Artifact - name: Upload NuGet Package As Artifact
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2

View file

@ -1,18 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<EnableDefaultItems>false</EnableDefaultItems>
<AssemblyName>Physac-cs</AssemblyName>
<RootNamespace>Physac_cs</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<Compile Include="Physac.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../Raylib-cs/Raylib-cs.csproj" />
</ItemGroup>
</Project>

View file

@ -1,230 +0,0 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security;
using Raylib_cs;
namespace Physac_cs
{
public enum PhysicsShapeType
{
PHYSICS_CIRCLE,
PHYSICS_POLYGON
}
// Matrix2x2 type (used for polygon shape rotation matrix)
[StructLayout(LayoutKind.Sequential)]
public struct Matrix2x2
{
public float m00;
public float m01;
public float m10;
public float m11;
}
// @TODO Custom array marshall issue https://github.com/ChrisDill/Raylib-cs/issues/9
// Hack same as raylib.cs _MaterialMap_e_FixedBuffer
// No easy way to marshall arrays of custom types. no idea why?
public unsafe struct _Polygon_e_FixedBuffer
{
public Vector2 v0;
public Vector2 v1;
public Vector2 v2;
public Vector2 v3;
public Vector2 v4;
public Vector2 v5;
public Vector2 v6;
public Vector2 v7;
public Vector2 v8;
public Vector2 v9;
public Vector2 v10;
public Vector2 v11;
public Vector2 v12;
public Vector2 v13;
public Vector2 v14;
public Vector2 v15;
public Vector2 v16;
public Vector2 v17;
public Vector2 v18;
public Vector2 v19;
public Vector2 v20;
public Vector2 v21;
public Vector2 v22;
public Vector2 v23;
public Vector2 v24;
public Vector2 this[int index]
{
get
{
fixed (Vector2* e = &v0)
return e[index];
}
}
}
[StructLayout(LayoutKind.Sequential)]
public struct PhysicsVertexData
{
public uint vertexCount; // Vertex count (positions and normals)
public _Polygon_e_FixedBuffer positions; // Vertex positions vectors
public _Polygon_e_FixedBuffer normals; // Vertex normals vectors
}
[StructLayout(LayoutKind.Sequential)]
public struct PhysicsShape
{
public PhysicsShapeType type; // Shape type (circle or polygon)
public IntPtr body; // Shape physics body reference
public PhysicsVertexData vertexData; // Shape vertices data (used for polygon shapes)
public float radius; // Shape radius (used for circle shapes)
public Matrix2x2 transform; // Vertices transform matrix 2x2
}
[StructLayout(LayoutKind.Sequential)]
public struct PhysicsBodyData
{
public uint id; // Unique identifier
public byte enabled; // Enabled dynamics state (collisions are calculated anyway)
public Vector2 position; // Physics body shape pivot
public Vector2 velocity; // Current linear velocity applied to position
public Vector2 force; // Current linear force (reset to 0 every step)
public float angularVelocity; // Current angular velocity applied to orient
public float torque; // Current angular force (reset to 0 every step)
public float orient; // Rotation in radians
public float inertia; // Moment of inertia
public float inverseInertia; // Inverse value of inertia
public float mass; // Physics body mass
public float inverseMass; // Inverse value of mass
public float staticFriction; // Friction when the body has not movement (0 to 1)
public float dynamicFriction; // Friction when the body has movement (0 to 1)
public float restitution; // Restitution coefficient of the body (0 to 1)
public byte useGravity; // Apply gravity force to dynamics
public byte isGrounded; // Physics grounded on other body state
public byte freezeOrient; // Physics rotation constraint
public PhysicsShape shape; // Physics body shape information (type, radius, vertices, transform)
}
[StructLayout(LayoutKind.Sequential)]
public struct PhysicsManifoldData
{
public uint id; // Reference unique identifier
public IntPtr bodyA; // Manifold first physics body reference
public IntPtr bodyB; // Manifold second physics body reference
public float penetration; // Depth of penetration from collision
public Vector2 normal; // Normal direction vector from 'a' to 'b'
public Vector2 contactsA; // Points of contact during collision
public Vector2 contactsB; // Points of contact during collision
public uint contactsCount; // Current collision number of contacts
public float restitution; // Mixed restitution during collision
public float dynamicFriction; // Mixed dynamic friction during collision
public float staticFriction; // Mixed static friction during collision
}
[SuppressUnmanagedCodeSecurity]
public static class Physac
{
// Used by DllImport to load the native library.
public const string nativeLibName = "physac";
public const int PHYSAC_MAX_BODIES = 64;
public const int PHYSAC_MAX_MANIFOLDS = 4096;
public const int PHYSAC_MAX_VERTICES = 24;
public const int PHYSAC_CIRCLE_VERTICES = 24;
public const int PHYSAC_COLLISION_ITERATIONS = 100;
public const float PHYSAC_PENETRATION_ALLOWANCE = 0.05f;
public const float PHYSAC_PENETRATION_CORRECTION = 0.4f;
// Physics system management
// Initializes physics values, pointers and creates physics loop thread
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void InitPhysics();
// Update physics system
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void UpdatePhysics();
// Reset physics system (global variables)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void ResetPhysics();
// Close physics system and unload used memory
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void ClosePhysics();
// Sets physics fixed time step in milliseconds. 1.666666 by default
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SetPhysicsTimeStep(double delta);
// Sets physics global gravity force
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SetPhysicsGravity(float x, float y);
// Physic body creation/destroy
// Creates a new circle physics body with generic parameters
// IntPtr refers to a PhysicsBodyData *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr CreatePhysicsBodyCircle(Vector2 pos, float radius, float density);
// Creates a new rectangle physics body with generic parameters
// IntPtr refers to a PhysicsBodyData *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr CreatePhysicsBodyRectangle(Vector2 pos, float width, float height, float density);
// Creates a new polygon physics body with generic parameters
// IntPtr refers to a PhysicsBodyData *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr CreatePhysicsBodyPolygon(Vector2 pos, float radius, int sides, float density);
// Destroy a physics body
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void DestroyPhysicsBody(PhysicsBodyData body);
// Physic body forces
// Adds a force to a physics body
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void PhysicsAddForce(PhysicsBodyData body, Vector2 force);
// Adds an angular force to a physics body
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void PhysicsAddTorque(PhysicsBodyData body, float amount);
// Shatters a polygon shape physics body to little physics bodies with explosion force
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void PhysicsShatter(PhysicsBodyData body, Vector2 position, float force);
// Sets physics body shape transform based on radians parameter
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SetPhysicsBodyRotation(PhysicsBodyData body, float radians);
// Query physics info
// Returns a physics body of the bodies pool at a specific index
// IntPtr refers to a PhysicsBodyData *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr GetPhysicsBody(int index);
// Returns the current amount of created physics bodies
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int GetPhysicsBodiesCount();
// Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int GetPhysicsShapeType(int index);
// Returns the amount of vertices of a physics body shape
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int GetPhysicsShapeVerticesCount(int index);
// Returns transformed position of a body shape (body position + vertex transformed position)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 GetPhysicsShapeVertex(PhysicsBodyData body, int vertex);
}
}

View file

@ -1,8 +1,8 @@
![Raylib-cs Logo](https://github.com/ChrisDill/Raylib-cs/blob/master/Logo/raylib-cs_256x256.png "Raylib-cs Logo") ![Raylib-cs Logo](https://raw.githubusercontent.com/ChrisDill/Raylib-cs/master/Logo/raylib-cs_256x256.png "Raylib-cs Logo")
# Raylib-cs # Raylib-cs
C# bindings for raylib 3.7.0, a simple and easy-to-use library to learn videogames programming (www.raylib.com) C# bindings for raylib 4.0.0, a simple and easy-to-use library to learn videogames programming (www.raylib.com)
[![GitHub contributors](https://img.shields.io/github/contributors/ChrisDill/Raylib-cs)](https://github.com/ChrisDill/Raylib-cs/graphs/contributors) [![GitHub contributors](https://img.shields.io/github/contributors/ChrisDill/Raylib-cs)](https://github.com/ChrisDill/Raylib-cs/graphs/contributors)
[![License](https://img.shields.io/badge/license-zlib%2Flibpng-blue.svg)](LICENSE) [![License](https://img.shields.io/badge/license-zlib%2Flibpng-blue.svg)](LICENSE)
@ -12,14 +12,14 @@ C# bindings for raylib 3.7.0, a simple and easy-to-use library to learn videogam
[![Build](https://github.com/ChrisDill/Raylib-cs/workflows/Build/badge.svg)](https://github.com/ChrisDill/Raylib-cs/actions?query=workflow%3ABuild) [![Build](https://github.com/ChrisDill/Raylib-cs/workflows/Build/badge.svg)](https://github.com/ChrisDill/Raylib-cs/actions?query=workflow%3ABuild)
Raylib-cs targets netstandard2.1 and supports netcoreapp3.0+ and net5.0. Raylib-cs targets net5.0 and net6.0.
## Installation - NuGet ## Installation - NuGet
This is the prefered method to get started - The package is still new so please report any [issues](https://github.com/ChrisDill/Raylib-cs/issues). This is the prefered method to get started - The package is still new so please report any [issues](https://github.com/ChrisDill/Raylib-cs/issues).
``` ```
dotnet add package Raylib-cs --version 3.7.0.1 dotnet add package Raylib-cs --version 4.0.0
``` ```
[![NuGet](https://img.shields.io/nuget/dt/raylib-cs)](https://www.nuget.org/packages/Raylib-cs/) [![NuGet](https://img.shields.io/nuget/dt/raylib-cs)](https://www.nuget.org/packages/Raylib-cs/)
@ -30,9 +30,9 @@ If you need to edit Raylib-cs source then you will need to add the bindings as a
1. Download/Clone this repo 1. Download/Clone this repo
2. Add Raylib-cs/Raylib-cs.csproj to your project as an existing project. 2. Add [Raylib-cs/Raylib-cs.csproj](Raylib-cs/Raylib-cs.csproj) to your project as an existing project.
3. Download the native libraries for the platforms you want to build for using the [official 3.7.0 release](https://github.com/raysan5/raylib/releases/tag/3.7.0). 3. Download the native libraries for the platforms you want to build for using the [official 4.0.0 release](https://github.com/raysan5/raylib/releases/tag/4.0.0).
**NOTE: the MSVC version is required for Windows platforms** **NOTE: the MSVC version is required for Windows platforms**
4. **(Recommended)** Put the native library for each platform under `Raylib-cs/runtimes/{platform}/native/` 4. **(Recommended)** Put the native library for each platform under `Raylib-cs/runtimes/{platform}/native/`
@ -40,6 +40,8 @@ If you need to edit Raylib-cs source then you will need to add the bindings as a
5. Start coding! 5. Start coding!
## Hello, World!
```csharp ```csharp
using Raylib_cs; using Raylib_cs;
@ -67,10 +69,6 @@ namespace HelloWorld
} }
``` ```
## Physac-cs and Raygui-cs
There are **UNSUPPORTED & EXPERIMENTAL** bindings to physac and raygui. They are in separate projects not included in releases or via NuGet. Pull requests are welcome and encouraged.
## Documentation ## Documentation
Examples for Raylib-cs can be found at [Raylib-cs-Examples](https://github.com/ChrisDill/Raylib-cs-Examples). Examples for Raylib-cs can be found at [Raylib-cs-Examples](https://github.com/ChrisDill/Raylib-cs-Examples).

View file

@ -1,18 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<EnableDefaultItems>false</EnableDefaultItems>
<AssemblyName>Raygui-cs</AssemblyName>
<RootNamespace>Raygui_cs</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<Compile Include="Raygui.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../Raylib-cs/Raylib-cs.csproj" />
</ItemGroup>
</Project>

View file

@ -1,454 +0,0 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using Raylib_cs;
namespace Raygui_cs
{
// Style property
[StructLayout(LayoutKind.Sequential)]
struct GuiStyleProp
{
ushort controlId;
ushort propertyId;
int propertyValue;
}
// Gui global state enum
public enum GuiControlState
{
GUI_STATE_NORMAL = 0,
GUI_STATE_FOCUSED,
GUI_STATE_PRESSED,
GUI_STATE_DISABLED,
}
// Gui global text alignment
public enum GuiTextAlignment
{
GUI_TEXT_ALIGN_LEFT = 0,
GUI_TEXT_ALIGN_CENTER,
GUI_TEXT_ALIGN_RIGHT,
}
// Gui standard controls
public enum GuiControl
{
DEFAULT = 0,
LABEL, // LABELBUTTON
BUTTON, // IMAGEBUTTON
TOGGLE, // TOGGLEGROUP
SLIDER, // SLIDERBAR
PROGRESSBAR,
CHECKBOX,
COMBOBOX,
DROPDOWNBOX,
TEXTBOX, // TEXTBOXMULTI
VALUEBOX,
SPINNER,
LISTVIEW,
COLORPICKER,
SCROLLBAR,
STATUSBAR
}
// Gui default properties for every control
public enum GuiControlProperty
{
BORDER_COLOR_NORMAL = 0,
BASE_COLOR_NORMAL,
TEXT_COLOR_NORMAL,
BORDER_COLOR_FOCUSED,
BASE_COLOR_FOCUSED,
TEXT_COLOR_FOCUSED,
BORDER_COLOR_PRESSED,
BASE_COLOR_PRESSED,
TEXT_COLOR_PRESSED,
BORDER_COLOR_DISABLED,
BASE_COLOR_DISABLED,
TEXT_COLOR_DISABLED,
BORDER_WIDTH,
TEXT_PADDING,
TEXT_ALIGNMENT,
RESERVED
}
// Gui extended properties depending on control type
// NOTE: We reserve a fixed size of additional properties per control
// Default properties
public enum GuiDefaultProperty
{
TEXT_SIZE = 16,
TEXT_SPACING,
LINE_COLOR,
BACKGROUND_COLOR,
}
// Toggle / ToggleGroup
public enum GuiToggleProperty
{
GROUP_PADDING = 16,
}
// Slider / SliderBar
public enum GuiSliderProperty
{
SLIDER_WIDTH = 16,
TEXT_PADDING
}
// ProgressBar
public enum GuiProgressBarProperty
{
PROGRESS_PADDING = 16,
}
// CheckBox
public enum GuiCheckBoxProperty
{
CHECK_PADDING = 16
}
// ComboBox
public enum GuiComboBoxProperty
{
SELECTOR_WIDTH = 16,
SELECTOR_PADDING
}
// DropdownBox
public enum GuiDropdownBoxProperty
{
ARROW_PADDING = 16,
DROPDOWN_ITEMS_PADDING
}
// TextBox / TextBoxMulti / ValueBox / Spinner
public enum GuiTextBoxProperty
{
TEXT_INNER_PADDING = 16,
TEXT_LINES_PADDING,
COLOR_SELECTED_FG,
COLOR_SELECTED_BG
}
// Spinner
public enum GuiSpinnerProperty
{
SPIN_BUTTON_WIDTH = 16,
SPIN_BUTTON_PADDING,
}
// ScrollBar
public enum GuiScrollBarProperty
{
ARROWS_SIZE = 16,
ARROWS_VISIBLE,
SCROLL_SLIDER_PADDING,
SCROLL_SLIDER_SIZE,
SCROLL_PADDING,
SCROLL_SPEED,
}
// ScrollBar side
public enum GuiScrollBarSide
{
SCROLLBAR_LEFT_SIDE = 0,
SCROLLBAR_RIGHT_SIDE
}
// ListView
public enum GuiListViewProperty
{
LIST_ITEMS_HEIGHT = 16,
LIST_ITEMS_PADDING,
SCROLLBAR_WIDTH,
SCROLLBAR_SIDE,
}
// ColorPicker
public enum GuiColorPickerProperty
{
COLOR_SELECTOR_SIZE = 16,
HUEBAR_WIDTH, // Right hue bar width
HUEBAR_PADDING, // Right hue bar separation from panel
HUEBAR_SELECTOR_HEIGHT, // Right hue bar selector height
HUEBAR_SELECTOR_OVERFLOW // Right hue bar selector overflow
}
[SuppressUnmanagedCodeSecurity]
public static class Raygui
{
// Used by DllImport to load the native library.
public const string nativeLibName = "raygui";
public const string RAYGUI_VERSION = "2.9-dev";
public const int NUM_CONTROLS = 16; // Number of standard controls
public const int NUM_PROPS_DEFAULT = 16; // Number of standard properties
public const int NUM_PROPS_EXTENDED = 8; // Number of extended properties
public const int TEXTEDIT_CURSOR_BLINK_FRAMES = 20; // Text edit controls cursor blink timming
// State modification functions
// Enable gui controls (global state)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiEnable();
// Disable gui controls (global state)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiDisable();
// Lock gui controls (global state)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiLock();
// Unlock gui controls (global state)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiUnlock();
// Set gui controls alpha (global state), alpha goes from 0.0f to 1.0f
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiFade(float alpha);
// Set gui state (global state)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiSetState(int state);
// Get gui state (global state)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiGetState();
// Font set/get functions
// Get gui custom font (global state)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiSetFont(Font font);
// Set gui custom font (global state)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Font GuiGetFont();
// Style set/get functions
// Set one style property
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiSetStyle(GuiControl control, GuiControlProperty property, int value);
// Get one style property
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiGetStyle(GuiControl control, GuiControlProperty property);
// Container/separator controls, useful for controls organization
// Window Box control, shows a window that can be closed
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool GuiWindowBox(Rectangle bounds, string text);
// Group Box control with title name
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiGroupBox(Rectangle bounds, string text);
// Line separator control
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiLine(Rectangle bounds, string text);
// Panel control, useful to group controls
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiPanel(Rectangle bounds);
// Scroll Panel control
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Rectangle GuiScrollPanel(Rectangle bounds, Rectangle content, ref Vector2 scroll);
// Basic controls set
// Label control, shows text
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiLabel(Rectangle bounds, string text);
// Button control, returns true when clicked
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool GuiButton(Rectangle bounds, string text);
// Label button control, show true when clicked
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool GuiLabelButton(Rectangle bounds, string text);
// Image button control, returns true when clicked
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool GuiImageButton(Rectangle bounds, string text, Texture2D texture);
// Image button extended control, returns true when clicked
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool GuiImageButtonEx(Rectangle bounds, string text, Texture2D texture, Rectangle texSource);
// Toggle Button control, returns true when active
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool GuiToggle(Rectangle bounds, string text, bool active);
// Toggle Group control, returns active toggle index
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiToggleGroup(Rectangle bounds, string text, int active);
// Check Box control, returns true when active
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool GuiCheckBox(Rectangle bounds, string text, bool isChecked);
// Combo Box control, returns selected item index
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiComboBox(Rectangle bounds, string text, int active);
// Dropdown Box control, returns selected item
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool GuiDropdownBox(Rectangle bounds, string text, ref int active, bool editMode);
// Spinner control, returns selected value
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool GuiSpinner(Rectangle bounds, string text, ref int value, int minValue, int maxValue, bool editMode);
// Value Box control, updates input text with numbers
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool GuiValueBox(Rectangle bounds, string text, ref int value, int minValue, int maxValue, bool editMode);
// Text Box control, updates input text
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool GuiTextBox(Rectangle bounds, StringBuilder text, int textSize, bool freeEdit);
// Text Box control with multiple lines
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool GuiTextBoxMulti(Rectangle bounds, StringBuilder text, int textSize, bool editMode);
// Slider control, returns selected value
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float GuiSlider(Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue);
// Slider Bar control, returns selected value
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float GuiSliderBar(Rectangle bounds, float value, float minValue, float maxValue);
// Progress Bar control, shows current progress value
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float GuiProgressBar(Rectangle bounds, float value, float minValue, float maxValue);
// Status Bar control, shows info text
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiStatusBar(Rectangle bounds, string text);
// Dummy control for placeholders
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiDummyRec(Rectangle bounds, string text);
// Scroll Bar control
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue);
// Grid
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 GuiGrid(Rectangle bounds, float spacing, int subdivs);
// Advance controls set
// List View control, returns selected list element index
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiListView(Rectangle bounds, string text, ref int scrollIndex, ref int active);
// List View with extended parameters
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiListViewEx(Rectangle bounds, string text, int count, ref int focus, ref int scrollIndex, ref int active);
// Message Box control, displays a message
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiMessageBox(Rectangle bounds, string title, string message);
// Text Input Box control, ask for text
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiTextInputBox(Rectangle bounds, string windowTitle, string message, string buttons, string text);
// Color Picker control
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Color GuiColorPicker(Rectangle bounds, Color color);
// Color Panel control
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Color GuiColorPanel(Rectangle bounds, Color color);
// Color Bar Alpha control
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float GuiColorBarAlpha(Rectangle bounds, float alpha);
// Color Bar Hue control
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float GuiColorBarHue(Rectangle bounds, float value);
// Styles loading functions
// Load style file (.rgs)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiLoadStyle(string fileName);
// Load style default over global style
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiLoadStyleDefault();
// Get text with icon id prepended (if supported)
[DllImport(nativeLibName, EntryPoint = "GetMonitorName", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr INTERNAL_GuiIconText(int iconId, string text);
public static string GuiIconText(int iconId, string text)
{
return Marshal.PtrToStringUTF8(INTERNAL_GuiIconText(iconId, text));
}
// Gui icons functionality
// Get full icons data pointer
// IntPtr refers to a unsigned int *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr GuiGetIcons();
// Get icon bit data
// IntPtr refers to a unsigned int *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr GuiGetIconData(int iconId, string text);
// Set icon bit data
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiSetIconData(int iconId, uint[] data);
// Set icon pixel value
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiSetIconPixel(int iconId, int x, int y);
// Clear icon pixel value
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiClearIconPixel(int iconId, int x, int y);
// Check icon pixel value
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool GuiCheckIconPixel(int iconId, int x, int y);
}
}

View file

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net5.0</TargetFrameworks> <TargetFramework>net6.0</TargetFramework>
<ApplicationIcon>../Logo/raylib-cs.ico</ApplicationIcon> <ApplicationIcon>../Logo/raylib-cs.ico</ApplicationIcon>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
@ -13,6 +13,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="../Raylib-cs/Raylib-cs.csproj" /> <PackageReference Include="Raylib-cs" Version="4.0.0-alpha.2" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -1,43 +1,95 @@
using System; using System;
using Xunit; using Xunit;
using Raylib_cs;
namespace Raylib_cs.Tests namespace Raylib_cs.Tests
{ {
public class RaylibTests public class RaylibTests
{ {
// Test if binding structs are blittable. private unsafe void CheckType<T>() where T : unmanaged
[Fact]
public void IsBlittable()
{ {
Assert.True(BlittableHelper.IsBlittable<Color>()); Assert.True(BlittableHelper.IsBlittable<T>());
Assert.True(BlittableHelper.IsBlittable<Rectangle>()); }
Assert.True(BlittableHelper.IsBlittable<Image>());
Assert.True(BlittableHelper.IsBlittable<Texture2D>()); [Fact]
Assert.True(BlittableHelper.IsBlittable<RenderTexture2D>()); public void CheckTypes()
Assert.True(BlittableHelper.IsBlittable<NPatchInfo>()); {
Assert.True(BlittableHelper.IsBlittable<CharInfo>()); CheckType<Color>();
Assert.True(BlittableHelper.IsBlittable<Font>()); CheckType<Rectangle>();
Assert.True(BlittableHelper.IsBlittable<Camera3D>()); CheckType<Image>();
Assert.True(BlittableHelper.IsBlittable<Camera2D>()); CheckType<Texture2D>();
Assert.True(BlittableHelper.IsBlittable<Mesh>()); CheckType<RenderTexture2D>();
Assert.True(BlittableHelper.IsBlittable<Shader>()); CheckType<NPatchInfo>();
Assert.True(BlittableHelper.IsBlittable<MaterialMap>()); CheckType<GlyphInfo>();
Assert.True(BlittableHelper.IsBlittable<Material>()); CheckType<Font>();
Assert.True(BlittableHelper.IsBlittable<Transform>()); CheckType<Camera2D>();
Assert.True(BlittableHelper.IsBlittable<BoneInfo>()); CheckType<Camera3D>();
Assert.True(BlittableHelper.IsBlittable<Model>()); CheckType<Mesh>();
Assert.True(BlittableHelper.IsBlittable<Model>()); CheckType<Shader>();
Assert.True(BlittableHelper.IsBlittable<ModelAnimation>()); CheckType<MaterialMap>();
Assert.True(BlittableHelper.IsBlittable<Ray>()); CheckType<Material>();
Assert.True(BlittableHelper.IsBlittable<RayHitInfo>()); CheckType<Transform>();
Assert.True(BlittableHelper.IsBlittable<BoundingBox>()); CheckType<BoneInfo>();
Assert.True(BlittableHelper.IsBlittable<Wave>()); CheckType<Model>();
Assert.True(BlittableHelper.IsBlittable<AudioStream>()); CheckType<ModelAnimation>();
Assert.True(BlittableHelper.IsBlittable<Sound>()); CheckType<Ray>();
Assert.True(BlittableHelper.IsBlittable<Music>()); CheckType<RayCollision>();
Assert.True(BlittableHelper.IsBlittable<VrDeviceInfo>()); CheckType<BoundingBox>();
Assert.True(BlittableHelper.IsBlittable<VrStereoConfig>()); CheckType<Wave>();
Assert.True(BlittableHelper.IsBlittable<RenderBatch>()); CheckType<AudioStream>();
CheckType<Sound>();
CheckType<Music>();
CheckType<VrDeviceInfo>();
CheckType<VrStereoConfig>();
CheckType<RenderBatch>();
}
[Fact]
public void TextToInteger()
{
int value = Raylib.TextToInteger("99999");
Assert.Equal(99999, value);
}
[Fact]
public void TextToPascal()
{
string input = "hello_world";
string text = Raylib.TextToPascal(input).ToString();
Assert.Equal("HelloWorld", text);
}
[Fact]
public void LoadCodepoints()
{
int count = 0;
string input = "aàáâãäāăąȧXǎȁȃeèéêẽëē";
int[] codepoints1 = Raylib.LoadCodepoints(input, ref count);
for (int i = 0; i < input.Length; i++)
{
Assert.Equal(input[i], codepoints1[i]);
}
}
[Fact]
public void CodepointToUTF8()
{
int byteSize = 0;
string text = Raylib.CodepointToUTF8(224, ref byteSize).ToString();
Assert.Equal("à", text);
}
[Fact]
public void TextCodepointsToUTF8()
{
string input = "aàáâãäāăąȧXǎȁȃeèéêẽëē";
int count = 0;
int[] codepoints1 = Raylib.LoadCodepoints(input, ref count);
string text = Raylib.TextCodepointsToUTF8(codepoints1, codepoints1.Length).ToString();
Assert.Equal(input, text);
} }
} }
} }

View file

@ -1,264 +0,0 @@
using System;
namespace Raylib_cs
{
public static class Easings
{
// Linear Easing functions
public static float EaseLinearNone(float t, float b, float c, float d)
{
return (c * t / d + b);
}
public static float EaseLinearIn(float t, float b, float c, float d)
{
return (c * t / d + b);
}
public static float EaseLinearOut(float t, float b, float c, float d)
{
return (c * t / d + b);
}
public static float EaseLinearInOut(float t, float b, float c, float d)
{
return (c * t / d + b);
}
// Sine Easing functions
public static float EaseSineIn(float t, float b, float c, float d)
{
return (-c * MathF.Cos(t / d * (MathF.PI / 2)) + c + b);
}
public static float EaseSineOut(float t, float b, float c, float d)
{
return (c * MathF.Sin(t / d * (MathF.PI / 2)) + b);
}
public static float EaseSineInOut(float t, float b, float c, float d)
{
return (-c / 2 * (MathF.Cos(MathF.PI * t / d) - 1) + b);
}
// Circular Easing functions
public static float EaseCircIn(float t, float b, float c, float d)
{
return (-c * (MathF.Sqrt(1 - (t /= d) * t) - 1) + b);
}
public static float EaseCircOut(float t, float b, float c, float d)
{
return (c * MathF.Sqrt(1 - (t = t / d - 1) * t) + b);
}
public static float EaseCircInOut(float t, float b, float c, float d)
{
if ((t /= d / 2) < 1)
{
return (-c / 2 * (MathF.Sqrt(1 - t * t) - 1) + b);
}
return (c / 2 * (MathF.Sqrt(1 - t * (t -= 2)) + 1) + b);
}
// Cubic Easing functions
public static float EaseCubicIn(float t, float b, float c, float d)
{
return (c * (t /= d) * t * t + b);
}
public static float EaseCubicOut(float t, float b, float c, float d)
{
return (c * ((t = t / d - 1) * t * t + 1) + b);
}
public static float EaseCubicInOut(float t, float b, float c, float d)
{
if ((t /= d / 2) < 1)
{
return (c / 2 * t * t * t + b);
}
return (c / 2 * ((t -= 2) * t * t + 2) + b);
}
// Quadratic Easing functions
public static float EaseQuadIn(float t, float b, float c, float d)
{
return (c * (t /= d) * t + b);
}
public static float EaseQuadOut(float t, float b, float c, float d)
{
return (-c * (t /= d) * (t - 2) + b);
}
public static float EaseQuadInOut(float t, float b, float c, float d)
{
if ((t /= d / 2) < 1)
{
return (((c / 2) * (t * t)) + b);
}
return (-c / 2 * (((t - 2) * (--t)) - 1) + b);
}
// Exponential Easing functions
public static float EaseExpoIn(float t, float b, float c, float d)
{
return (t == 0) ? b : (c * MathF.Pow(2, 10 * (t / d - 1)) + b);
}
public static float EaseExpoOut(float t, float b, float c, float d)
{
return (t == d) ? (b + c) : (c * (-MathF.Pow(2, -10 * t / d) + 1) + b);
}
public static float EaseExpoInOut(float t, float b, float c, float d)
{
if (t == 0)
{
return b;
}
if (t == d)
{
return (b + c);
}
if ((t /= d / 2) < 1)
{
return (c / 2 * MathF.Pow(2, 10 * (t - 1)) + b);
}
return (c / 2 * (-MathF.Pow(2, -10 * --t) + 2) + b);
}
// Back Easing functions
public static float EaseBackIn(float t, float b, float c, float d)
{
float s = 1.70158f;
float postFix = t /= d;
return (c * (postFix) * t * ((s + 1) * t - s) + b);
}
public static float EaseBackOut(float t, float b, float c, float d)
{
float s = 1.70158f;
return (c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b);
}
public static float EaseBackInOut(float t, float b, float c, float d)
{
float s = 1.70158f;
if ((t /= d / 2) < 1)
{
return (c / 2 * (t * t * (((s *= (1.525f)) + 1) * t - s)) + b);
}
float postFix = t -= 2;
return (c / 2 * ((postFix) * t * (((s *= (1.525f)) + 1) * t + s) + 2) + b);
}
// Bounce Easing functions
public static float EaseBounceOut(float t, float b, float c, float d)
{
if ((t /= d) < (1 / 2.75f))
{
return (c * (7.5625f * t * t) + b);
}
else if (t < (2 / 2.75f))
{
float postFix = t -= (1.5f / 2.75f);
return (c * (7.5625f * (postFix) * t + 0.75f) + b);
}
else if (t < (2.5 / 2.75))
{
float postFix = t -= (2.25f / 2.75f);
return (c * (7.5625f * (postFix) * t + 0.9375f) + b);
}
else
{
float postFix = t -= (2.625f / 2.75f);
return (c * (7.5625f * (postFix) * t + 0.984375f) + b);
}
}
public static float EaseBounceIn(float t, float b, float c, float d)
{
return (c - EaseBounceOut(d - t, 0, c, d) + b);
}
public static float EaseBounceInOut(float t, float b, float c, float d)
{
if (t < d / 2)
{
return (EaseBounceIn(t * 2, 0, c, d) * 0.5f + b);
}
else
{
return (EaseBounceOut(t * 2 - d, 0, c, d) * 0.5f + c * 0.5f + b);
}
}
// Elastic Easing functions
public static float EaseElasticIn(float t, float b, float c, float d)
{
if (t == 0)
{
return b;
}
if ((t /= d) == 1)
{
return (b + c);
}
float p = d * 0.3f;
float a = c;
float s = p / 4;
float postFix = a * MathF.Pow(2, 10 * (t -= 1));
return (-(postFix * MathF.Sin((t * d - s) * (2 * MathF.PI) / p)) + b);
}
public static float EaseElasticOut(float t, float b, float c, float d)
{
if (t == 0)
{
return b;
}
if ((t /= d) == 1)
{
return (b + c);
}
float p = d * 0.3f;
float a = c;
float s = p / 4;
return (a * MathF.Pow(2, -10 * t) * MathF.Sin((t * d - s) * (2 * MathF.PI) / p) + c + b);
}
public static float EaseElasticInOut(float t, float b, float c, float d)
{
if (t == 0)
{
return b;
}
if ((t /= d / 2) == 2)
{
return (b + c);
}
float p = d * (0.3f * 1.5f);
float a = c;
float s = p / 4;
float postFix = 0f;
if (t < 1)
{
postFix = a * MathF.Pow(2, 10 * (t -= 1));
return -0.5f * (postFix * MathF.Sin((t * d - s) * (2 * MathF.PI) / p)) + b;
}
postFix = a * MathF.Pow(2, -10 * (t -= 1));
return (postFix * MathF.Sin((t * d - s) * (2 * MathF.PI) / p) * 0.5f + c + b);
}
}
}

View file

@ -1,26 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.1</TargetFrameworks> <TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<EnableDefaultItems>false</EnableDefaultItems> <EnableDefaultItems>false</EnableDefaultItems>
<AssemblyName>Raylib-cs</AssemblyName> <AssemblyName>Raylib-cs</AssemblyName>
<RootNamespace>Raylib_cs</RootNamespace> <RootNamespace>Raylib_cs</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<NoWarn>$(NoWarn);1591</NoWarn> <NoWarn>$(NoWarn);1591</NoWarn>
<LangVersion>10.0</LangVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<TargetRaylibTag>3.7.0</TargetRaylibTag> <TargetRaylibTag>4.0.0</TargetRaylibTag>
<Version>3.7.0.1</Version> <Version>4.0.0</Version>
<PackageVersion>3.7.0.1</PackageVersion> <PackageVersion>4.0.0</PackageVersion>
<Authors>Chris Dill, Raysan5 &amp; Others</Authors> <Authors>Chris Dill, Raysan5</Authors>
<PackProject>true</PackProject> <PackProject>true</PackProject>
<PackageLicenseExpression>Zlib</PackageLicenseExpression> <PackageLicenseExpression>Zlib</PackageLicenseExpression>
<Title>Raylib-cs</Title> <Title>Raylib-cs</Title>
<Description>C# bindings for raylib - A simple and easy-to-use library to learn videogames programming</Description> <Description>C# bindings for raylib - A simple and easy-to-use library to learn videogames programming</Description>
<PackageIcon>raylib-cs_64x64.png</PackageIcon> <PackageIcon>raylib-cs_64x64.png</PackageIcon>
<PackageTags>Raylib;Raysan;Gamedev;Binding</PackageTags> <PackageTags>raylib;bindings;gamedev</PackageTags>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/ChrisDill/Raylib-cs/</RepositoryUrl> <RepositoryUrl>https://github.com/ChrisDill/Raylib-cs/</RepositoryUrl>
<PackageProjectUrl>https://www.raylib.com/</PackageProjectUrl> <PackageProjectUrl>https://www.raylib.com/</PackageProjectUrl>
@ -28,15 +28,12 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Easings.cs"/> <None Include="../Logo/raylib-cs_64x64.png" Pack="true" PackagePath="" />
<Compile Include="Raylib.cs"/> <None Include="../README.md" Pack="true" PackagePath="" />
<Compile Include="Raymath.cs"/>
<Compile Include="Rlgl.cs"/>
<None Include="../Logo/raylib-cs_64x64.png" Pack="true" PackagePath=""/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0"/> <PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -46,4 +43,11 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Compile Include="interop\*.cs" />
<Compile Include="types\*.cs" />
<Compile Include="types\native\CBool.cs" />
<Compile Include="types\native\UTF8Buffer.cs" />
</ItemGroup>
</Project> </Project>

2157
Raylib-cs/interop/Raylib.cs Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,416 @@
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security;
namespace Raylib_cs
{
// NOTE: Helper types to be used instead of array return types for *ToFloat functions
public unsafe struct float3
{
public fixed float v[3];
}
public unsafe struct float16
{
public fixed float v[16];
}
[SuppressUnmanagedCodeSecurity]
public static unsafe partial class Raymath
{
/// <summary>
/// Used by DllImport to load the native library
/// </summary>
public const string nativeLibName = "raylib";
/// <summary>Clamp float value</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Clamp(float value, float min, float max);
/// <summary>Calculate linear interpolation between two vectors</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Lerp(float start, float end, float amount);
/// <summary>Normalize input value within input range</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Normalize(float value, float start, float end);
/// <summary>Remap input value within input range to output range</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Remap(float value, float inputStart, float inputEnd, float outputStart, float outputEnd);
/// <summary>Vector with components value 0.0f</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Zero();
/// <summary>Vector with components value 1.0f</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2One();
/// <summary>Add two vectors (v1 + v2)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Add(Vector2 v1, Vector2 v2);
/// <summary>Add vector and float value</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2AddValue(Vector2 v, float add);
/// <summary>Subtract two vectors (v1 - v2)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Subtract(Vector2 v1, Vector2 v2);
/// <summary>Subtract vector by float value</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2SubtractValue(Vector2 v, float sub);
/// <summary>Calculate vector length</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector2Length(Vector2 v);
/// <summary>Calculate vector square length</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector2LengthSqr(Vector2 v);
/// <summary>Calculate two vectors dot product</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector2DotProduct(Vector2 v1, Vector2 v2);
/// <summary>Calculate distance between two vectors</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector2Distance(Vector2 v1, Vector2 v2);
/// <summary>Calculate angle from two vectors in X-axis</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector2Angle(Vector2 v1, Vector2 v2);
/// <summary>Scale vector (multiply by value)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Scale(Vector2 v, float scale);
/// <summary>Multiply vector by vector</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Multiply(Vector2 v1, Vector2 v2);
/// <summary>Negate vector</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Negate(Vector2 v);
/// <summary>Divide vector by vector</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Divide(Vector2 v1, Vector2 v2);
/// <summary>Normalize provided vector</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Normalize(Vector2 v);
/// <summary>Calculate linear interpolation between two vectors</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Lerp(Vector2 v1, Vector2 v2, float amount);
/// <summary>Calculate linear interpolation between two vectors</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Rotate(Vector2 v, float degs);
/// <summary>Vector with components value 0.0f</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Zero();
/// <summary>Vector with components value 1.0f</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3One();
/// <summary>Add two vectors</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Add(Vector3 v1, Vector3 v2);
/// <summary>Add vector and float value</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3AddValue(Vector3 v, float add);
/// <summary>Subtract two vectors</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Subtract(Vector3 v1, Vector3 v2);
/// <summary>Subtract vector and float value</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3SubtractValue(Vector3 v, float sub);
/// <summary>Multiply vector by scalar</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Scale(Vector3 v, float scalar);
/// <summary>Multiply vector by vector</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Multiply(Vector3 v1, Vector3 v2);
/// <summary>Calculate two vectors cross product</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2);
/// <summary>Calculate one vector perpendicular vector</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Perpendicular(Vector3 v);
/// <summary>Calculate vector length</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector3Length(Vector3 v);
/// <summary>Calculate vector square length</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector3LengthSqr(Vector3 v);
/// <summary>Calculate two vectors dot product</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector3DotProduct(Vector3 v1, Vector3 v2);
/// <summary>Calculate distance between two vectors</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector3Distance(Vector3 v1, Vector3 v2);
/// <summary>Calculate angle between two vectors in XY and XZ</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector3Angle(Vector3 v1, Vector3 v2);
/// <summary>Negate provided vector (invert direction)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Negate(Vector3 v);
/// <summary>Divide vector by vector</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Divide(Vector3 v1, Vector3 v2);
/// <summary>Normalize provided vector</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Normalize(Vector3 v);
/// <summary>Orthonormalize provided vectors<br/>
/// Makes vectors normalized and orthogonal to each other<br/>
/// Gram-Schmidt function implementation</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void Vector3OrthoNormalize(Vector3* v1, Vector3* v2);
/// <summary>Transforms a Vector3 by a given Matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Transform(Vector3 v, Matrix4x4 mat);
/// <summary>Transform a vector by quaternion rotation</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3RotateByQuaternion(Vector3 v, Quaternion q);
/// <summary>Calculate linear interpolation between two vectors</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount);
/// <summary>Calculate reflected vector to normal</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Reflect(Vector3 v, Vector3 normal);
/// <summary>Return min value for each pair of components</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Min(Vector3 v1, Vector3 v2);
/// <summary>Return max value for each pair of components</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Max(Vector3 v1, Vector3 v2);
/// <summary>Compute barycenter coordinates (u, v, w) for point p with respect to triangle (a, b, c)<br/>
/// NOTE: Assumes P is on the plane of the triangle</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c);
/// <summary>Projects a Vector3 from screen space into object space<br/>
/// NOTE: We are avoiding calling other raymath functions despite available</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Unproject(Vector3 source, Matrix4x4 projection, Matrix4x4 view);
/// <summary>Get Vector3 as float array</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float3 Vector3ToFloatV(Vector3 v);
/// <summary>Compute matrix determinant</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float MatrixDeterminant(Matrix4x4 mat);
/// <summary>Get the trace of the matrix (sum of the values along the diagonal)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float MatrixTrace(Matrix4x4 mat);
/// <summary>Transposes provided matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixTranspose(Matrix4x4 mat);
/// <summary>Invert provided matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixInvert(Matrix4x4 mat);
/// <summary>Normalize provided matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixNormalize(Matrix4x4 mat);
/// <summary>Get identity matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixIdentity();
/// <summary>Add two matrices</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixAdd(Matrix4x4 left, Matrix4x4 right);
/// <summary>Subtract two matrices (left - right)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixSubtract(Matrix4x4 left, Matrix4x4 right);
/// <summary>Get two matrix multiplication<br/>
/// NOTE: When multiplying matrices... the order matters!</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixMultiply(Matrix4x4 left, Matrix4x4 right);
/// <summary>Get translation matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixTranslate(float x, float y, float z);
/// <summary>Create rotation matrix from axis and angle<br/>
/// NOTE: Angle should be provided in radians</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixRotate(Vector3 axis, float angle);
/// <summary>Get x-rotation matrix (angle in radians)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixRotateX(float angle);
/// <summary>Get y-rotation matrix (angle in radians)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixRotateY(float angle);
/// <summary>Get z-rotation matrix (angle in radians)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixRotateZ(float angle);
/// <summary>Get xyz-rotation matrix (angles in radians)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixRotateXYZ(Vector3 ang);
/// <summary>Get zyx-rotation matrix (angles in radians)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixRotateZYX(Vector3 ang);
/// <summary>Get scaling matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixScale(float x, float y, float z);
/// <summary>Get perspective projection matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixFrustum(double left, double right, double bottom, double top, double near, double far);
/// <summary>Get perspective projection matrix<br/>
/// NOTE: Angle should be provided in radians</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixPerspective(double fovy, double aspect, double near, double far);
/// <summary>Get orthographic projection matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixOrtho(double left, double right, double bottom, double top, double near, double far);
/// <summary>Get camera look-at matrix (view matrix)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up);
/// <summary>Get float array of matrix data</summary>
[DllImport(Raylib.nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float16 MatrixToFloatV(Matrix4x4 m);
/// <summary>Add 2 quaternions</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionAdd(Quaternion q1, Quaternion q2);
/// <summary>Add quaternion and float value</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionAddValue(Quaternion q, float add);
/// <summary>Subtract 2 quaternions</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionSubtract(Quaternion q1, Quaternion q2);
/// <summary>Subtract quaternion and float value</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionSubtractValue(Quaternion q, float add);
/// <summary>Get identity quaternion</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionIdentity();
/// <summary>Computes the length of a quaternion</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float QuaternionLength(Quaternion q);
/// <summary>Normalize provided quaternion</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionNormalize(Quaternion q);
/// <summary>Invert provided quaternion</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionInvert(Quaternion q);
/// <summary>Calculate two quaternion multiplication</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2);
/// <summary>Scale quaternion by float value</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionScale(Quaternion q, float mul);
/// <summary>Divide two quaternions</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionDivide(Quaternion q1, Quaternion q2);
/// <summary>Calculate linear interpolation between two quaternions</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionLerp(Quaternion q1, Quaternion q2, float amount);
/// <summary>Calculate slerp-optimized interpolation between two quaternions</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionNlerp(Quaternion q1, Quaternion q2, float amount);
/// <summary>Calculates spherical linear interpolation between two quaternions</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount);
/// <summary>Calculate quaternion based on the rotation from one vector to another</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to);
/// <summary>Get a quaternion for a given rotation matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionFromMatrix(Matrix4x4 mat);
/// <summary>Get a matrix for a given quaternion</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 QuaternionToMatrix(Quaternion q);
/// <summary>Get rotation quaternion for an angle and axis<br/>
/// NOTE: angle must be provided in radians</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle);
/// <summary>Get the rotation angle and axis for a given quaternion</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void QuaternionToAxisAngle(Quaternion q, Vector3* outAxis, float* outAngle);
/// <summary>Get the quaternion equivalent to Euler angles<br/>
/// NOTE: Rotation order is ZYX</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionFromEuler(float pitch, float yaw, float roll);
/// <summary>Get the Euler angles equivalent to quaternion (roll, pitch, yaw)<br/>
/// NOTE: Angles are returned in a Vector3 struct in radians</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 QuaternionToEuler(Quaternion q);
/// <summary>Transform a quaternion given a transformation matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionTransform(Quaternion q, Matrix4x4 mat);
}
}

699
Raylib-cs/interop/Rlgl.cs Normal file
View file

@ -0,0 +1,699 @@
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security;
namespace Raylib_cs
{
[SuppressUnmanagedCodeSecurity]
public static unsafe partial class Rlgl
{
/// <summary>
/// Used by DllImport to load the native library
/// </summary>
public const string nativeLibName = "raylib";
public const int DEFAULT_BATCH_BUFFER_ELEMENTS = 8192;
public const int DEFAULT_BATCH_BUFFERS = 1;
public const int DEFAULT_BATCH_DRAWCALLS = 256;
public const int MAX_BATCH_ACTIVE_TEXTURES = 4;
public const int MAX_MATRIX_STACK_SIZE = 32;
public const float RL_CULL_DISTANCE_NEAR = 0.01f;
public const float RL_CULL_DISTANCE_FAR = 1000.0f;
// Texture parameters (equivalent to OpenGL defines)
public const int RL_TEXTURE_WRAP_S = 0x2802;
public const int RL_TEXTURE_WRAP_T = 0x2803;
public const int RL_TEXTURE_MAG_FILTER = 0x2800;
public const int RL_TEXTURE_MIN_FILTER = 0x2801;
public const int RL_TEXTURE_FILTER_NEAREST = 0x2600;
public const int RL_TEXTURE_FILTER_LINEAR = 0x2601;
public const int RL_TEXTURE_FILTER_MIP_NEAREST = 0x2700;
public const int RL_TEXTURE_FILTER_NEAREST_MIP_LINEAR = 0x2702;
public const int RL_TEXTURE_FILTER_LINEAR_MIP_NEAREST = 0x2701;
public const int RL_TEXTURE_FILTER_MIP_LINEAR = 0x2703;
public const int RL_TEXTURE_FILTER_ANISOTROPIC = 0x3000;
public const int RL_TEXTURE_WRAP_REPEAT = 0x2901;
public const int RL_TEXTURE_WRAP_CLAMP = 0x812F;
public const int RL_TEXTURE_WRAP_MIRROR_REPEAT = 0x8370;
public const int RL_TEXTURE_WRAP_MIRROR_CLAMP = 0x8742;
// GL equivalent data types
public const int RL_UNSIGNED_BYTE = 0x1401;
public const int RL_FLOAT = 0x1406;
// Buffer usage hint
public const int RL_STREAM_DRAW = 0x88E0;
public const int RL_STREAM_READ = 0x88E1;
public const int RL_STREAM_COPY = 0x88E2;
public const int RL_STATIC_DRAW = 0x88E4;
public const int RL_STATIC_READ = 0x88E5;
public const int RL_STATIC_COPY = 0x88E6;
public const int RL_DYNAMIC_DRAW = 0x88E8;
public const int RL_DYNAMIC_READ = 0x88E9;
public const int RL_DYNAMIC_COPY = 0x88EA;
// ------------------------------------------------------------------------------------
// Functions Declaration - Matrix operations
// ------------------------------------------------------------------------------------
/// <summary>Choose the current matrix to be transformed</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlMatrixMode(int mode);
public static void rlMatrixMode(MatrixMode mode)
{
rlMatrixMode((int)mode);
}
/// <summary>Push the current matrix to stack</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlPushMatrix();
/// <summary>Pop lattest inserted matrix from stack</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlPopMatrix();
/// <summary>Reset current matrix to identity matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlLoadIdentity();
/// <summary>Multiply the current matrix by a translation matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlTranslatef(float x, float y, float z);
/// <summary>Multiply the current matrix by a rotation matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlRotatef(float angle, float x, float y, float z);
/// <summary>Multiply the current matrix by a scaling matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlScalef(float x, float y, float z);
/// <summary>
/// Multiply the current matrix by another matrix
/// <br/>
/// Current Matrix can be set via <see cref="rlMatrixMode(int)"/>
/// </summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlMultMatrixf(float* matf);
/// <inheritdoc cref="rlMultMatrixf(float*)"/>
public static void rlMultMatrixf(Matrix4x4 matf)
{
float16 f = Raymath.MatrixToFloatV(matf);
rlMultMatrixf(f.v);
}
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlOrtho(double left, double right, double bottom, double top, double znear, double zfar);
/// <summary>Set the viewport area</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlViewport(int x, int y, int width, int height);
// ------------------------------------------------------------------------------------
// Functions Declaration - Vertex level operations
// ------------------------------------------------------------------------------------
/// <summary>Initialize drawing mode (how to organize vertex)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlBegin(int mode);
public static void rlBegin(DrawMode mode)
{
rlBegin((int)mode);
}
/// <summary>Finish vertex providing</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnd();
/// <summary>Define one vertex (position) - 2 int</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlVertex2i(int x, int y);
/// <summary>Define one vertex (position) - 2 float</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlVertex2f(float x, float y);
/// <summary>Define one vertex (position) - 3 float</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlVertex3f(float x, float y, float z);
/// <summary>Define one vertex (texture coordinate) - 2 float</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlTexCoord2f(float x, float y);
/// <summary>Define one vertex (normal) - 3 float</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlNormal3f(float x, float y, float z);
/// <summary>Define one vertex (color) - 4 byte</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlColor4ub(byte r, byte g, byte b, byte a);
/// <summary>Define one vertex (color) - 3 float</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlColor3f(float x, float y, float z);
/// <summary>Define one vertex (color) - 4 float</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlColor4f(float x, float y, float z, float w);
// ------------------------------------------------------------------------------------
// Functions Declaration - OpenGL equivalent functions (common to 1.1, 3.3+, ES2)
// NOTE: This functions are used to completely abstract raylib code from OpenGL layer
// ------------------------------------------------------------------------------------
/// <summary>Vertex buffers state</summary>
/// <summary>Enable vertex array (VAO, if supported)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern CBool rlEnableVertexArray(uint vaoId);
/// <summary>Disable vertex array (VAO, if supported)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableVertexArray();
/// <summary>Enable vertex buffer (VBO)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableVertexBuffer(uint id);
/// <summary>Disable vertex buffer (VBO)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableVertexBuffer();
/// <summary>Enable vertex buffer element (VBO element)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableVertexBufferElement(uint id);
/// <summary>Disable vertex buffer element (VBO element)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableVertexBufferElement();
/// <summary>Enable vertex attribute index</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableVertexAttribute(uint index);
/// <summary>Disable vertex attribute index</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableVertexAttribute(uint index);
/// <summary>Enable attribute state pointer<br/>
/// NOTE: Only available for GRAPHICS_API_OPENGL_11</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableStatePointer(int vertexAttribType, void* buffer);
/// <summary>Disable attribute state pointer<br/>
/// NOTE: Only available for GRAPHICS_API_OPENGL_11</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableStatePointer(int vertexAttribType);
// Textures state
/// <summary>Select and active a texture slot</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlActiveTextureSlot(int slot);
/// <summary>Enable texture</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableTexture(uint id);
/// <summary>Disable texture</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableTexture();
/// <summary>Enable texture cubemap</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableTextureCubemap(uint id);
/// <summary>Disable texture cubemap</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableTextureCubemap();
/// <summary>Set texture parameters (filter, wrap)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlTextureParameters(uint id, int param, int value);
// Shader state
/// <summary>Enable shader program</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableShader(uint id);
/// <summary>Disable shader program</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableShader();
// Framebuffer state
/// <summary>Enable render texture (fbo)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableFramebuffer(uint id);
/// <summary>Disable render texture (fbo), return to default framebuffer</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableFramebuffer();
/// <summary>Activate multiple draw color buffers</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlActiveDrawBuffers(int count);
// General render state
/// <summary>Enable color blending</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableColorBlend();
/// <summary>Disable color blending</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableColorBlend();
/// <summary>Enable depth test</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableDepthTest();
/// <summary>Disable depth test</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableDepthTest();
/// <summary>Enable depth write</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableDepthMask();
/// <summary>Disable depth write</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableDepthMask();
/// <summary>Enable backface culling</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableBackfaceCulling();
/// <summary>Disable backface culling</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableBackfaceCulling();
/// <summary>Enable scissor test</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableScissorTest();
/// <summary>Disable scissor test</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableScissorTest();
/// <summary>Scissor test</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlScissor(int x, int y, int width, int height);
/// <summary>Enable wire mode</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableWireMode();
/// <summary>Disable wire mode</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableWireMode();
/// <summary>Set the line drawing width</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetLineWidth(float width);
/// <summary>Get the line drawing width</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float rlGetLineWidth();
/// <summary>Enable line aliasing</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableSmoothLines();
/// <summary>Disable line aliasing</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableSmoothLines();
/// <summary>Enable stereo rendering</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlEnableStereoRender();
/// <summary>Disable stereo rendering</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDisableStereoRender();
/// <summary>Check if stereo render is enabled</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern CBool rlIsStereoRenderEnabled();
/// <summary>Clear color buffer with color</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlClearColor(byte r, byte g, byte b, byte a);
/// <summary>Clear used screen buffers (color and depth)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlClearScreenBuffers();
/// <summary>Check and log OpenGL error codes</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlCheckErrors();
/// <summary>Set blending mode</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetBlendMode(BlendMode mode);
/// <summary>Set blending mode factor and equation (using OpenGL factors)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetBlendFactors(int glSrcFactor, int glDstFactor, int glEquation);
// ------------------------------------------------------------------------------------
// Functions Declaration - rlgl functionality
// ------------------------------------------------------------------------------------
/// <summary>Initialize rlgl (buffers, shaders, textures, states)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlglInit(int width, int height);
/// <summary>De-inititialize rlgl (buffers, shaders, textures)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlglClose();
/// <summary>Load OpenGL extensions</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlLoadExtensions(void* loader);
/// <summary>Get current OpenGL version</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern GlVersion rlGetVersion();
/// <summary>Get default framebuffer width</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int rlGetFramebufferWidth();
/// <summary>Get default framebuffer height</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int rlGetFramebufferHeight();
/// <summary>Get default texture</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlGetTextureIdDefault();
/// <summary>Get default shader</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlGetShaderIdDefault();
/// <summary>Get default shader locations</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int* rlGetShaderLocsDefault();
// Render batch management
/// <summary>Load a render batch system<br/>
/// NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode<br/>
/// but this render batch API is exposed in case custom batches are required</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern RenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements);
/// <summary>Unload render batch system</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlUnloadRenderBatch(RenderBatch batch);
/// <summary>Draw render batch data (Update->Draw->Reset)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDrawRenderBatch(RenderBatch* batch);
/// <summary>Set the active render batch for rlgl (NULL for default internal)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetRenderBatchActive(RenderBatch* batch);
/// <summary>Update and draw internal render batch</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDrawRenderBatchActive();
/// <summary>Check internal buffer overflow for a given number of vertex</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern CBool rlCheckRenderBatchLimit(int vCount);
/// <summary>Set current texture for render batch and check buffers limits</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetTexture(uint id);
// Vertex buffers management
/// <summary>Load vertex array (vao) if supported</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadVertexArray();
/// <summary>Load a vertex buffer attribute</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadVertexBuffer(void* buffer, int size, CBool dynamic);
/// <summary>Load a new attributes element buffer</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadVertexBufferElement(void* buffer, int size, CBool dynamic);
/// <summary>Update GPU buffer with new data</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlUpdateVertexBuffer(uint bufferId, void* data, int dataSize, int offset);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlUnloadVertexArray(uint vaoId);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlUnloadVertexBuffer(uint vboId);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetVertexAttribute(uint index, int compSize, int type, CBool normalized, int stride, void* pointer);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetVertexAttributeDivisor(uint index, int divisor);
/// <summary>Set vertex attribute default value</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetVertexAttributeDefault(int locIndex, void* value, int attribType, int count);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDrawVertexArray(int offset, int count);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDrawVertexArrayElements(int offset, int count, void* buffer);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDrawVertexArrayInstanced(int offset, int count, int instances);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDrawVertexArrayElementsInstanced(int offset, int count, void* buffer, int instances);
// Textures data management
/// <summary>Load texture in GPU</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadTexture(void* data, int width, int height, PixelFormat format, int mipmapCount);
/// <summary>Load depth texture/renderbuffer (to be attached to fbo)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadTextureDepth(int width, int height, CBool useRenderBuffer);
/// <summary>Load texture cubemap</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadTextureCubemap(void* data, int size, PixelFormat format);
/// <summary>Update GPU texture with new data</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlUpdateTexture(uint id, int width, int height, PixelFormat format, void* data);
/// <summary>Get OpenGL internal formats</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlGetGlTextureFormats(PixelFormat format, int* glInternalFormat, int* glFormat, int* glType);
/// <summary>Get OpenGL internal formats</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern sbyte* rlGetPixelFormatName(PixelFormat format);
/// <summary>Unload texture from GPU memory</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlUnloadTexture(uint id);
/// <summary>Generate mipmap data for selected texture</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlGenTextureMipmaps(uint id, int width, int height, PixelFormat format, int* mipmaps);
/// <summary>Read texture pixel data</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void* rlReadTexturePixels(uint id, int width, int height, PixelFormat format);
/// <summary>Read screen pixel data (color buffer)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern byte* rlReadScreenPixels(int width, int height);
// Framebuffer management (fbo)
/// <summary>Load an empty framebuffer</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadFramebuffer(int width, int height);
/// <summary>Attach texture/renderbuffer to a framebuffer</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlFramebufferAttach(uint fboId, uint texId, FramebufferAttachType attachType, FramebufferAttachTextureType texType, int mipLevel);
/// <summary>Verify framebuffer is complete</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern CBool rlFramebufferComplete(uint id);
/// <summary>Delete framebuffer from GPU</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern CBool rlUnloadFramebuffer(uint id);
// Shaders management
/// <summary>Load shader from code strings</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadShaderCode(sbyte* vsCode, sbyte* fsCode);
/// <summary>Compile custom shader and return shader id<br/>
/// (type: RL_VERTEX_SHADER, RL_FRAGMENT_SHADER, RL_COMPUTE_SHADER)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlCompileShader(sbyte* shaderCode, int type);
/// <summary>Load custom shader program</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadShaderProgram(uint vShaderId, uint fShaderId);
/// <summary>Unload shader program</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlUnloadShaderProgram(uint id);
/// <summary>Get shader location uniform</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int rlGetLocationUniform(uint shaderId, sbyte* uniformName);
/// <summary>Get shader location attribute</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int rlGetLocationAttrib(uint shaderId, sbyte* attribName);
/// <summary>Set shader value uniform</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetUniform(int locIndex, void* value, int uniformType, int count);
/// <summary>Set shader value matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetUniformMatrix(int locIndex, Matrix4x4 mat);
/// <summary>Set shader value sampler</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetUniformSampler(int locIndex, uint textureId);
/// <summary>Set shader currently active</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetShader(Shader shader);
// Compute shader management
/// <summary>Load compute shader program</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadComputeShaderProgram(uint shaderId);
/// <summary>Dispatch compute shader (equivalent to *draw* for graphics pilepine)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlComputeShaderDispatch(uint groupX, uint groupY, uint groupZ);
/// <summary>Load shader storage buffer object (SSBO)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadShaderBuffer(ulong size, void* data, int usageHint);
/// <summary>Unload shader storage buffer object (SSBO)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlUnloadShaderBuffer(uint ssboId);
/// <summary>Update SSBO buffer data</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlUpdateShaderBufferElements(Shader shader);
/// <summary>Get SSBO buffer size</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern ulong rlGetShaderBufferSize(uint id, void* dest, ulong count, ulong offset);
/// <summary>Bind SSBO buffer</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlReadShaderBufferElements(uint id, void* dest, ulong count, ulong offset);
/// <summary> Copy SSBO buffer data</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlBindShaderBuffer(uint id, uint index);
// Buffer management
/// <summary>Copy SSBO buffer data</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlCopyBuffersElements(uint destId, uint srcId, ulong destOffset, ulong srcOffset, ulong count);
/// <summary>Bind image texture</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlBindImageTexture(uint id, uint index, uint format, int readOnly);
// Matrix state management
/// <summary>Get internal modelview matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 rlGetMatrixModelview();
/// <summary>Get internal projection matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 rlGetMatrixProjection();
/// <summary>Get internal accumulated transform matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 rlGetMatrixTramsform();
/// <summary>Get internal projection matrix for stereo render (selected eye)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 rlGetMatrixProjectionStereo(int eye);
/// <summary>Get internal view offset matrix for stereo render (selected eye)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 rlGetMatrixViewOffsetStereo(int eye);
/// <summary>Set a custom projection matrix (replaces internal projection matrix)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetMatrixProjection(Matrix4x4 view);
/// <summary>Set a custom modelview matrix (replaces internal modelview matrix)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetMatrixModelview(Matrix4x4 proj);
/// <summary>Set eyes projection matrices for stereo rendering</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetMatrixProjectionStereo(Matrix4x4 left, Matrix4x4 right);
/// <summary>Set eyes view offsets matrices for stereo rendering</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetMatrixViewOffsetStereo(Matrix4x4 left, Matrix4x4 right);
// Quick and dirty cube/quad buffers load->draw->unload
/// <summary>Load and draw a cube</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlLoadDrawCube();
/// <summary>Load and draw a quad</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlLoadDrawQuad();
}
}

118
Raylib-cs/types/Audio.cs Normal file
View file

@ -0,0 +1,118 @@
using System;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// Wave type, defines audio wave data
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Wave
{
/// <summary>
/// Number of samples
/// </summary>
public uint sampleCount;
/// <summary>
/// Frequency (samples per second)
/// </summary>
public uint sampleRate;
/// <summary>
/// Bit depth (bits per sample): 8, 16, 32 (24 not supported)
/// </summary>
public uint sampleSize;
/// <summary>
/// Number of channels (1-mono, 2-stereo)
/// </summary>
public uint channels;
//TODO: SPAN<byte> ?
/// <summary>
/// Buffer data pointer
/// </summary>
public void* data;
}
/// <summary>
/// Audio stream type<br/>
/// NOTE: Useful to create custom audio streams not bound to a specific file
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct AudioStream
{
//TODO: convert
/// <summary>
/// Pointer to internal data(rAudioBuffer *) used by the audio system
/// </summary>
public IntPtr buffer;
/// <summary>
/// Frequency (samples per second)
/// </summary>
public uint sampleRate;
/// <summary>
/// Bit depth (bits per sample): 8, 16, 32 (24 not supported)
/// </summary>
public uint sampleSize;
/// <summary>
/// Number of channels (1-mono, 2-stereo)
/// </summary>
public uint channels;
}
/// <summary>
/// Sound source type
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct Sound
{
/// <summary>
/// Audio stream
/// </summary>
public AudioStream stream;
/// <summary>
/// Total number of frames (considering channels)
/// </summary>
public uint frameCount;
}
/// <summary>
/// Music stream type (audio file streaming from memory)<br/>
/// NOTE: Anything longer than ~10 seconds should be streamed
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Music
{
/// <summary>
/// Audio stream
/// </summary>
public AudioStream stream;
/// <summary>
/// Total number of samples
/// </summary>
public uint frameCount;
/// <summary>
/// Music looping enable
/// </summary>
public CBool looping;
/// <summary>
/// Type of music context (audio filetype)
/// </summary>
public int ctxType;
//TODO span
/// <summary>
/// Audio context data, depends on type
/// </summary>
public void* ctxData;
}
}

View file

@ -0,0 +1,26 @@
using System.Numerics;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>Bounding box type</summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct BoundingBox
{
/// <summary>
/// Minimum vertex box-corner
/// </summary>
public Vector3 min;
/// <summary>
/// Maximum vertex box-corner
/// </summary>
public Vector3 max;
public BoundingBox(Vector3 min, Vector3 max)
{
this.min = min;
this.max = max;
}
}
}

View file

@ -0,0 +1,40 @@
using System.Numerics;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// Camera2D, defines position/orientation in 2d space
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct Camera2D
{
/// <summary>
/// Camera offset (displacement from target)
/// </summary>
public Vector2 offset;
/// <summary>
/// Camera target (rotation and zoom origin)
/// </summary>
public Vector2 target;
/// <summary>
/// Camera rotation in degrees
/// </summary>
public float rotation;
/// <summary>
/// Camera zoom (scaling), should be 1.0f by default
/// </summary>
public float zoom;
public Camera2D(Vector2 offset, Vector2 target, float rotation, float zoom)
{
this.offset = offset;
this.target = target;
this.rotation = rotation;
this.zoom = zoom;
}
}
}

View file

@ -0,0 +1,67 @@
using System.Numerics;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// Camera system modes
/// </summary>
public enum CameraMode
{
CAMERA_CUSTOM = 0,
CAMERA_FREE,
CAMERA_ORBITAL,
CAMERA_FIRST_PERSON,
CAMERA_THIRD_PERSON
}
/// <summary>
/// Camera projection
/// </summary>
public enum CameraProjection
{
CAMERA_PERSPECTIVE = 0,
CAMERA_ORTHOGRAPHIC
}
/// <summary>
/// Camera3D, defines position/orientation in 3d space
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct Camera3D
{
/// <summary>
/// Camera position
/// </summary>
public Vector3 position;
/// <summary>
/// Camera target it looks-at
/// </summary>
public Vector3 target;
/// <summary>
/// Camera up vector (rotation over its axis)
/// </summary>
public Vector3 up;
/// <summary>
/// Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
/// </summary>
public float fovy;
/// <summary>
/// Camera type, defines projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
/// </summary>
public CameraProjection projection;
public Camera3D(Vector3 position, Vector3 target, Vector3 up, float fovy, CameraProjection projection)
{
this.position = position;
this.target = target;
this.up = up;
this.fovy = fovy;
this.projection = projection;
}
}
}

67
Raylib-cs/types/Color.cs Normal file
View file

@ -0,0 +1,67 @@
using System;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// Color type, RGBA (32bit)
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct Color
{
public byte r;
public byte g;
public byte b;
public byte a;
// Example - Color.RED instead of RED
// Custom raylib color palette for amazing visuals
public static Color LIGHTGRAY = new Color(200, 200, 200, 255);
public static Color GRAY = new Color(130, 130, 130, 255);
public static Color DARKGRAY = new Color(80, 80, 80, 255);
public static Color YELLOW = new Color(253, 249, 0, 255);
public static Color GOLD = new Color(255, 203, 0, 255);
public static Color ORANGE = new Color(255, 161, 0, 255);
public static Color PINK = new Color(255, 109, 194, 255);
public static Color RED = new Color(230, 41, 55, 255);
public static Color MAROON = new Color(190, 33, 55, 255);
public static Color GREEN = new Color(0, 228, 48, 255);
public static Color LIME = new Color(0, 158, 47, 255);
public static Color DARKGREEN = new Color(0, 117, 44, 255);
public static Color SKYBLUE = new Color(102, 191, 255, 255);
public static Color BLUE = new Color(0, 121, 241, 255);
public static Color DARKBLUE = new Color(0, 82, 172, 255);
public static Color PURPLE = new Color(200, 122, 255, 255);
public static Color VIOLET = new Color(135, 60, 190, 255);
public static Color DARKPURPLE = new Color(112, 31, 126, 255);
public static Color BEIGE = new Color(211, 176, 131, 255);
public static Color BROWN = new Color(127, 106, 79, 255);
public static Color DARKBROWN = new Color(76, 63, 47, 255);
public static Color WHITE = new Color(255, 255, 255, 255);
public static Color BLACK = new Color(0, 0, 0, 255);
public static Color BLANK = new Color(0, 0, 0, 0);
public static Color MAGENTA = new Color(255, 0, 255, 255);
public static Color RAYWHITE = new Color(245, 245, 245, 255);
public Color(byte r, byte g, byte b, byte a)
{
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}
public Color(int r, int g, int b, int a)
{
this.r = Convert.ToByte(r);
this.g = Convert.ToByte(g);
this.b = Convert.ToByte(b);
this.a = Convert.ToByte(a);
}
public override string ToString()
{
return $"{{R:{r} G:{g} B:{b} A:{a}}}";
}
}
}

166
Raylib-cs/types/Core.cs Normal file
View file

@ -0,0 +1,166 @@
using System;
namespace Raylib_cs
{
/// <summary>
/// System config flags<br/>
/// NOTE: Every bit registers one state (use it with bit masks)<br/>
/// By default all flags are set to 0
/// </summary>
[Flags]
public enum ConfigFlags : uint
{
/// <summary>
/// Set to try enabling V-Sync on GPU
/// </summary>
FLAG_VSYNC_HINT = 0x00000040,
/// <summary>
/// Set to run program in fullscreen
/// </summary>
FLAG_FULLSCREEN_MODE = 0x00000002,
/// <summary>
/// Set to allow resizable window
/// </summary>
FLAG_WINDOW_RESIZABLE = 0x00000004,
/// <summary>
/// Set to disable window decoration (frame and buttons)
/// </summary>
FLAG_WINDOW_UNDECORATED = 0x00000008,
/// <summary>
/// Set to hide window
/// </summary>
FLAG_WINDOW_HIDDEN = 0x00000080,
/// <summary>
/// Set to minimize window (iconify)
/// </summary>
FLAG_WINDOW_MINIMIZED = 0x00000200,
/// <summary>
/// Set to maximize window (expanded to monitor)
/// </summary>
FLAG_WINDOW_MAXIMIZED = 0x00000400,
/// <summary>
/// Set to window non focused
/// </summary>
FLAG_WINDOW_UNFOCUSED = 0x00000800,
/// <summary>
/// Set to window always on top
/// </summary>
FLAG_WINDOW_TOPMOST = 0x00001000,
/// <summary>
/// Set to allow windows running while minimized
/// </summary>
FLAG_WINDOW_ALWAYS_RUN = 0x00000100,
/// <summary>
/// Set to allow transparent framebuffer
/// </summary>
FLAG_WINDOW_TRANSPARENT = 0x00000010,
/// <summary>
/// Set to support HighDPI
/// </summary>
FLAG_WINDOW_HIGHDPI = 0x00002000,
/// <summary>
/// Set to try enabling MSAA 4X
/// </summary>
FLAG_MSAA_4X_HINT = 0x00000020,
/// <summary>
/// Set to try enabling interlaced video format (for V3D)
/// </summary>
FLAG_INTERLACED_HINT = 0x00010000,
}
/// <summary>
/// Trace log level<br/>
/// NOTE: Organized by priority level
/// </summary>
public enum TraceLogLevel
{
/// <summary>
/// Display all logs
/// </summary>
LOG_ALL = 0,
/// <summary>
/// Trace logging, intended for internal use only
/// </summary>
LOG_TRACE,
/// <summary>
/// Debug logging, used for internal debugging, it should be disabled on release builds
/// </summary>
LOG_DEBUG,
/// <summary>
/// Info logging, used for program execution info
/// </summary>
LOG_INFO,
/// <summary>
/// Warning logging, used on recoverable failures
/// </summary>
LOG_WARNING,
/// <summary>
/// Error logging, used on unrecoverable failures
/// </summary>
LOG_ERROR,
/// <summary>
/// Fatal logging, used to abort program: exit(EXIT_FAILURE)
/// </summary>
LOG_FATAL,
/// <summary>
/// Disable logging
/// </summary>
LOG_NONE
}
/// <summary>
/// Color blending modes (pre-defined)
/// </summary>
public enum BlendMode
{
/// <summary>
/// Blend textures considering alpha (default)
/// </summary>
BLEND_ALPHA = 0,
/// <summary>
/// Blend textures adding colors
/// </summary>
BLEND_ADDITIVE,
/// <summary>
/// Blend textures multiplying colors
/// </summary>
BLEND_MULTIPLIED,
/// <summary>
/// Blend textures adding colors (alternative)
/// </summary>
BLEND_ADD_COLORS,
/// <summary>
/// Blend textures subtracting colors (alternative)
/// </summary>
BLEND_SUBTRACT_COLORS,
/// <summary>
/// Blend textures using custom src/dst factors (use rlSetBlendMode())
/// </summary>
BLEND_CUSTOM
}
}

95
Raylib-cs/types/Font.cs Normal file
View file

@ -0,0 +1,95 @@
using System;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// Font type, defines generation method
/// </summary>
public enum FontType
{
/// <summary>
/// Default font generation, anti-aliased
/// </summary>
FONT_DEFAULT = 0,
/// <summary>
/// Bitmap font generation, no anti-aliasing
/// </summary>
FONT_BITMAP,
/// <summary>
/// SDF font generation, requires external shader
/// </summary>
FONT_SDF
}
/// <summary>
/// GlyphInfo, font characters glyphs info
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct GlyphInfo
{
/// <summary>
/// Character value (Unicode)
/// </summary>
public int value;
/// <summary>
/// Character offset X when drawing
/// </summary>
public int offsetX;
/// <summary>
/// Character offset Y when drawing
/// </summary>
public int offsetY;
/// <summary>
/// Character advance position X
/// </summary>
public int advanceX;
/// <summary>
/// Character image data
/// </summary>
public Image image;
}
/// <summary>
/// Font, font texture and GlyphInfo array data
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Font
{
/// <summary>
/// Base size (default chars height)
/// </summary>
public int baseSize;
/// <summary>
/// Number of characters
/// </summary>
public int glyphCount;
/// <summary>
/// Padding around the glyph characters
/// </summary>
public int glyphPadding;
/// <summary>
/// Texture atlas containing the glyphs
/// </summary>
public Texture2D texture;
/// <summary>
/// Rectangles in texture for the glyphs
/// </summary>
public Rectangle* recs;
/// <summary>
/// Glyphs info data
/// </summary>
public GlyphInfo* glyphs;
}
}

Some files were not shown because too many files have changed in this diff Show more