2
0
mirror of https://github.com/raylib-cs/raylib-cs synced 2025-06-30 19:03:42 -04:00
* 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:
2022-02-14 12:53:44 +00:00
committed by Ben Parsons
parent 15bbfc2968
commit e5934b86ba
38 changed files with 4454 additions and 3436 deletions

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

File diff suppressed because it is too large Load Diff

View File

@ -16,333 +16,400 @@ namespace Raylib_cs
}
[SuppressUnmanagedCodeSecurity]
public static class Raymath
public static unsafe partial class Raymath
{
// Used by DllImport to load the native library.
/// <summary>
/// Used by DllImport to load the native library
/// </summary>
public const string nativeLibName = "raylib";
// Clamp float value
/// <summary>Clamp float value</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Clamp(float value, float min, float max);
// Calculate linear interpolation between two vectors
/// <summary>Calculate linear interpolation between two vectors</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Lerp(float start, float end, float amount);
// Vector with components value 0.0f
/// <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();
// Vector with components value 1.0f
/// <summary>Vector with components value 1.0f</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2One();
// Add two vectors (v1 + v2)
/// <summary>Add two vectors (v1 + v2)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Add(Vector2 v1, Vector2 v2);
// Subtract two vectors (v1 - 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);
// Calculate vector length
/// <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);
// Calculate two vectors dot product
/// <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);
// Calculate distance between two vectors
/// <summary>Calculate distance between two vectors</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector2Distance(Vector2 v1, Vector2 v2);
// Calculate angle from two vectors in X-axis
/// <summary>Calculate angle from two vectors in X-axis</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector2Angle(Vector2 v1, Vector2 v2);
// Scale vector (multiply by value)
/// <summary>Scale vector (multiply by value)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Scale(Vector2 v, float scale);
// Multiply vector by vector
/// <summary>Multiply vector by vector</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2MultiplyV(Vector2 v1, Vector2 v2);
public static extern Vector2 Vector2Multiply(Vector2 v1, Vector2 v2);
// Negate vector
/// <summary>Negate vector</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Negate(Vector2 v);
// Divide vector by a float value
/// <summary>Divide vector by vector</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Divide(Vector2 v, float div);
public static extern Vector2 Vector2Divide(Vector2 v1, Vector2 v2);
// Divide vector by vector
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2DivideV(Vector2 v1, Vector2 v2);
// Normalize provided vector
/// <summary>Normalize provided vector</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Normalize(Vector2 v);
// Calculate linear interpolation between two vectors
/// <summary>Calculate linear interpolation between two vectors</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Lerp(Vector2 v1, Vector2 v2, float amount);
// Calculate linear interpolation between two vectors
/// <summary>Calculate linear interpolation between two vectors</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Rotate(Vector2 v, float degs);
// Vector with components value 0.0f
/// <summary>Vector with components value 0.0f</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Zero();
// Vector with components value 1.0f
/// <summary>Vector with components value 1.0f</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3One();
// Add two vectors
/// <summary>Add two vectors</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Add(Vector3 v1, Vector3 v2);
// Subtract two vectors
/// <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);
// Multiply vector by scalar
/// <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);
// Multiply vector by vector
/// <summary>Multiply vector by vector</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Multiply(Vector3 v1, Vector3 v2);
// Calculate two vectors cross product
/// <summary>Calculate two vectors cross product</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2);
// Calculate one vector perpendicular vector
/// <summary>Calculate one vector perpendicular vector</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Perpendicular(Vector3 v);
// Calculate vector length
/// <summary>Calculate vector length</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector3Length(Vector3 v);
// Calculate two vectors dot product
/// <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);
// Calculate distance between two vectors
/// <summary>Calculate distance between two vectors</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector3Distance(Vector3 v1, Vector3 v2);
// Negate provided vector (invert direction)
/// <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);
// Divide vector by a float value
/// <summary>Divide vector by vector</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Divide(Vector3 v, float div);
public static extern Vector3 Vector3Divide(Vector3 v1, Vector3 v2);
// Divide vector by vector
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3DivideV(Vector3 v1, Vector3 v2);
// Normalize provided vector
/// <summary>Normalize provided vector</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Normalize(Vector3 v);
// Orthonormalize provided vectors
// Makes vectors normalized and orthogonal to each other
// Gram-Schmidt function implementation
/// <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(ref Vector3 v1, ref Vector3 v2);
public static extern void Vector3OrthoNormalize(Vector3* v1, Vector3* v2);
// Transforms a Vector3 by a given Matrix
/// <summary>Transforms a Vector3 by a given Matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Transform(Vector3 v, Matrix4x4 mat);
// Transform a vector by quaternion rotation
/// <summary>Transform a vector by quaternion rotation</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3RotateByQuaternion(Vector3 v, Quaternion q);
// Calculate linear interpolation between two vectors
/// <summary>Calculate linear interpolation between two vectors</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount);
// Calculate reflected vector to normal
/// <summary>Calculate reflected vector to normal</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Reflect(Vector3 v, Vector3 normal);
// Return min value for each pair of components
/// <summary>Return min value for each pair of components</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Min(Vector3 v1, Vector3 v2);
// Return max value for each pair of components
/// <summary>Return max value for each pair of components</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Max(Vector3 v1, Vector3 v2);
// Compute barycenter coordinates (u, v, w) for point p with respect to triangle (a, b, c)
// NOTE: Assumes P is on the plane of the triangle
/// <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);
// Returns Vector3 as float array
/// <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);
// Compute matrix determinant
/// <summary>Compute matrix determinant</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float MatrixDeterminant(Matrix4x4 mat);
// Returns the trace of the matrix (sum of the values along the diagonal)
/// <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);
// Transposes provided matrix
/// <summary>Transposes provided matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixTranspose(Matrix4x4 mat);
// Invert provided matrix
/// <summary>Invert provided matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixInvert(Matrix4x4 mat);
// Normalize provided matrix
/// <summary>Normalize provided matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixNormalize(Matrix4x4 mat);
// Returns identity matrix
/// <summary>Get identity matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixIdentity();
// Add two matrices
/// <summary>Add two matrices</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixAdd(Matrix4x4 left, Matrix4x4 right);
// Subtract two matrices (left - right)
/// <summary>Subtract two matrices (left - right)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixSubtract(Matrix4x4 left, Matrix4x4 right);
// Returns translation matrix
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixTranslate(float x, float y, float z);
// Create rotation matrix from axis and angle
// NOTE: Angle should be provided in radians
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixRotate(Vector3 axis, float angle);
// Returns xyz-rotation matrix (angles in radians)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixRotateXYZ(Vector3 ang);
// Returns x-rotation matrix (angle in radians)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixRotateX(float angle);
// Returns y-rotation matrix (angle in radians)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixRotateY(float angle);
// Returns z-rotation matrix (angle in radians)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixRotateZ(float angle);
// Returns scaling matrix
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 MatrixScale(float x, float y, float z);
// Returns two matrix multiplication
// NOTE: When multiplying matrices... the order matters!
/// <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);
// Returns perspective projection matrix
/// <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);
// Returns perspective projection matrix
// NOTE: Angle should be provided in radians
/// <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);
// Returns orthographic projection matrix
/// <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);
// Returns camera look-at matrix (view matrix)
/// <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);
// Returns float array of matrix data
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float16 MatrixToFloatV(Matrix4x4 mat);
/// <summary>Get float array of matrix data</summary>
[DllImport(Raylib.nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float16 MatrixToFloatV(Matrix4x4 m);
// Returns identity quaternion
/// <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();
// Computes the length of a quaternion
/// <summary>Computes the length of a quaternion</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float QuaternionLength(Quaternion q);
// Normalize provided quaternion
/// <summary>Normalize provided quaternion</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionNormalize(Quaternion q);
// Invert provided quaternion
/// <summary>Invert provided quaternion</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionInvert(Quaternion q);
// Calculate two quaternion multiplication
/// <summary>Calculate two quaternion multiplication</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2);
// Calculate linear interpolation between two quaternions
/// <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);
// Calculate slerp-optimized interpolation between two quaternions
/// <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);
// Calculates spherical linear interpolation between two quaternions
/// <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);
// Calculate quaternion based on the rotation from one vector to another
/// <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);
// Returns a quaternion for a given rotation matrix
/// <summary>Get a quaternion for a given rotation matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionFromMatrix(Matrix4x4 mat);
// Returns a matrix for a given quaternion
/// <summary>Get a matrix for a given quaternion</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix4x4 QuaternionToMatrix(Quaternion q);
// Returns rotation quaternion for an angle and axis
// NOTE: angle must be provided in radians
/// <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);
// Returns the rotation angle and axis for a given quaternion
/// <summary>Get the rotation angle and axis for a given quaternion</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void QuaternionToAxisAngle(Quaternion q, ref Vector3 outAxis, ref float outAngle);
public static extern void QuaternionToAxisAngle(Quaternion q, Vector3* outAxis, float* outAngle);
// Returns he quaternion equivalent to Euler angles
/// <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 roll, float pitch, float yaw);
public static extern Quaternion QuaternionFromEuler(float pitch, float yaw, float roll);
// Return the Euler angles equivalent to quaternion (roll, pitch, yaw)
// NOTE: Angles are returned in a Vector3 struct in degrees
/// <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);
// Transform a quaternion given a transformation matrix
/// <summary>Transform a quaternion given a transformation matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionTransform(Quaternion q, Matrix4x4 mat);
}

View File

@ -1,61 +1,15 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security;
namespace Raylib_cs
{
/// <summary>RenderBatch type</summary>
[StructLayout(LayoutKind.Sequential)]
public struct RenderBatch
{
int buffersCount; // Number of vertex buffers (multi-buffering support)
int currentBuffer; // Current buffer tracking in case of multi-buffering
IntPtr vertexBuffer; // Dynamic buffer(s) for vertex data
IntPtr draws; // Draw calls array, depends on textureId
int drawsCounter; // Draw calls counter
float currentDepth; // Current depth value for next draw
}
public enum GlVersion
{
OPENGL_11 = 1,
OPENGL_21,
OPENGL_33,
OPENGL_ES_20
}
public enum FramebufferAttachType
{
RL_ATTACHMENT_COLOR_CHANNEL0 = 0,
RL_ATTACHMENT_COLOR_CHANNEL1,
RL_ATTACHMENT_COLOR_CHANNEL2,
RL_ATTACHMENT_COLOR_CHANNEL3,
RL_ATTACHMENT_COLOR_CHANNEL4,
RL_ATTACHMENT_COLOR_CHANNEL5,
RL_ATTACHMENT_COLOR_CHANNEL6,
RL_ATTACHMENT_COLOR_CHANNEL7,
RL_ATTACHMENT_DEPTH = 100,
RL_ATTACHMENT_STENCIL = 200,
}
public enum FramebufferAttachTextureType
{
RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0,
RL_ATTACHMENT_CUBEMAP_NEGATIVE_X,
RL_ATTACHMENT_CUBEMAP_POSITIVE_Y,
RL_ATTACHMENT_CUBEMAP_NEGATIVE_Y,
RL_ATTACHMENT_CUBEMAP_POSITIVE_Z,
RL_ATTACHMENT_CUBEMAP_NEGATIVE_Z,
RL_ATTACHMENT_TEXTURE2D = 100,
RL_ATTACHMENT_RENDERBUFFER = 200,
}
[SuppressUnmanagedCodeSecurity]
public static class Rlgl
public static unsafe partial class Rlgl
{
// Used by DllImport to load the native library.
/// <summary>
/// Used by DllImport to load the native library
/// </summary>
public const string nativeLibName = "raylib";
public const int DEFAULT_BATCH_BUFFER_ELEMENTS = 8192;
@ -85,20 +39,23 @@ namespace Raylib_cs
public const int RL_TEXTURE_WRAP_MIRROR_REPEAT = 0x8370;
public const int RL_TEXTURE_WRAP_MIRROR_CLAMP = 0x8742;
// Matrix modes (equivalent to OpenGL)
public const int RL_MODELVIEW = 0x1700;
public const int RL_PROJECTION = 0x1701;
public const int RL_TEXTURE = 0x1702;
// Primitive assembly draw modes
public const int RL_LINES = 0x0001;
public const int RL_TRIANGLES = 0x0004;
public const int RL_QUADS = 0x0007;
// 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
// ------------------------------------------------------------------------------------
@ -107,6 +64,11 @@ namespace Raylib_cs
[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();
@ -125,15 +87,26 @@ namespace Raylib_cs
/// <summary>Multiply the current matrix by a rotation matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlRotatef(float angleDeg, float x, float y, float z);
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</summary>
/// <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(ref float[] matf);
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);
@ -154,6 +127,11 @@ namespace Raylib_cs
[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();
@ -200,8 +178,7 @@ namespace Raylib_cs
/// <summary>Enable vertex array (VAO, if supported)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool rlEnableVertexArray(uint vaoId);
public static extern CBool rlEnableVertexArray(uint vaoId);
/// <summary>Disable vertex array (VAO, if supported)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -231,6 +208,16 @@ namespace Raylib_cs
[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
@ -280,9 +267,21 @@ namespace Raylib_cs
[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();
@ -353,8 +352,7 @@ namespace Raylib_cs
/// <summary>Check if stereo render is enabled</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool rlIsStereoRenderEnabled();
public static extern CBool rlIsStereoRenderEnabled();
/// <summary>Clear color buffer with color</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -370,11 +368,11 @@ namespace Raylib_cs
/// <summary>Set blending mode</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetBlendMode(int mode);
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 rlSetBlendModeFactors(int glSrcFactor, int glDstFactor, int glEquation);
public static extern void rlSetBlendFactors(int glSrcFactor, int glDstFactor, int glEquation);
// ------------------------------------------------------------------------------------
@ -390,11 +388,10 @@ namespace Raylib_cs
public static extern void rlglClose();
/// <summary>Load OpenGL extensions</summary>
/// <summary>loader refers to a void *</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlLoadExtensions(IntPtr loader);
public static extern void rlLoadExtensions(void* loader);
/// <summary>Returns current OpenGL version</summary>
/// <summary>Get current OpenGL version</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern GlVersion rlGetVersion();
@ -406,18 +403,23 @@ namespace Raylib_cs
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int rlGetFramebufferHeight();
/// <summary>Get default shader</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Shader rlGetShaderDefault();
/// <summary>Get default texture</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Texture2D rlGetTextureDefault();
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</summary>
/// <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);
@ -427,11 +429,11 @@ namespace Raylib_cs
/// <summary>Draw render batch data (Update->Draw->Reset)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlDrawRenderBatch(ref RenderBatch batch);
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(ref RenderBatch batch);
public static extern void rlSetRenderBatchActive(RenderBatch* batch);
/// <summary>Update and draw internal render batch</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -439,8 +441,7 @@ namespace Raylib_cs
/// <summary>Check internal buffer overflow for a given number of vertex</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool rlCheckRenderBatchLimit(int vCount);
public static extern CBool rlCheckRenderBatchLimit(int vCount);
/// <summary>Set current texture for render batch and check buffers limits</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -455,15 +456,15 @@ namespace Raylib_cs
/// <summary>Load a vertex buffer attribute</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadVertexBuffer(IntPtr buffer, int size, bool dynamic);
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(IntPtr buffer, int size, bool dynamic);
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(int bufferId, IntPtr data, int dataSize, int offset);
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);
@ -472,52 +473,53 @@ namespace Raylib_cs
public static extern void rlUnloadVertexBuffer(uint vboId);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetVertexAttribute(uint index, int compSize, int type, bool normalized, int stride, IntPtr pointer);
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, IntPtr value, int attribType, int count);
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, IntPtr buffer);
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, IntPtr buffer, int instances);
public static extern void rlDrawVertexArrayElementsInstanced(int offset, int count, void* buffer, int instances);
// Textures data management
/// <summary>Load texture in GPU
/// data refers to a void *</summary>
/// <summary>Load texture in GPU</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadTexture(IntPtr data, int width, int height, PixelFormat format, int mipmapCount);
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, bool useRenderBuffer);
public static extern uint rlLoadTextureDepth(int width, int height, CBool useRenderBuffer);
/// <summary>Load texture cubemap
/// data refers to a void *</summary>
/// <summary>Load texture cubemap</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint rlLoadTextureCubemap(IntPtr data, int size, PixelFormat format);
public static extern uint rlLoadTextureCubemap(void* data, int size, PixelFormat format);
/// <summary>Update GPU texture with new data
/// data refers to a const void *</summary>
/// <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, IntPtr data);
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, ref uint glInternalFormat, ref uint glFormat, ref uint glType);
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)]
@ -525,17 +527,15 @@ namespace Raylib_cs
/// <summary>Generate mipmap data for selected texture</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlGenerateMipmaps(ref Texture2D texture);
public static extern void rlGenTextureMipmaps(uint id, int width, int height, PixelFormat format, int* mipmaps);
/// <summary>Read texture pixel data
/// IntPtr refers to a void *</summary>
/// <summary>Read texture pixel data</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr rlReadTexturePixels(Texture2D texture);
public static extern void* rlReadTexturePixels(uint id, int width, int height, PixelFormat format);
/// <summary>Read screen pixel data (color buffer)
/// IntPtr refers to a unsigned char *</summary>
/// <summary>Read screen pixel data (color buffer)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr rlReadScreenPixels(int width, int height);
public static extern byte* rlReadScreenPixels(int width, int height);
// Framebuffer management (fbo)
@ -550,24 +550,23 @@ namespace Raylib_cs
/// <summary>Verify framebuffer is complete</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool rlFramebufferComplete(uint id);
public static extern CBool rlFramebufferComplete(uint id);
/// <summary>Delete framebuffer from GPU</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool rlUnloadFramebuffer(uint id);
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(string vsCode, string fsCode);
public static extern uint rlLoadShaderCode(sbyte* vsCode, sbyte* fsCode);
/// <summary>Compile custom shader and return shader id (type: GL_VERTEX_SHADER, GL_FRAGMENT_SHADER)</summary>
/// <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(string shaderCode, int type);
public static extern uint rlCompileShader(sbyte* shaderCode, int type);
/// <summary>Load custom shader program</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -579,15 +578,15 @@ namespace Raylib_cs
/// <summary>Get shader location uniform</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int rlGetLocationUniform(uint shaderId, string uniformName);
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, string attribName);
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, IntPtr value, int uniformType, int count);
public static extern void rlSetUniform(int locIndex, void* value, int uniformType, int count);
/// <summary>Set shader value matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -602,11 +601,57 @@ namespace Raylib_cs
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();
public static extern Matrix4x4 rlGetMatrixModelview();
/// <summary>Get internal projection matrix</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -630,7 +675,7 @@ namespace Raylib_cs
/// <summary>Set a custom modelview matrix (replaces internal modelview matrix)</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void rlSetMatrixModelView(Matrix4x4 proj);
public static extern void rlSetMatrixModelview(Matrix4x4 proj);
/// <summary>Set eyes projection matrices for stereo rendering</summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]

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;
}
}

149
Raylib-cs/types/Image.cs Normal file
View File

@ -0,0 +1,149 @@
using System;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// Pixel formats<br/>
/// NOTE: Support depends on OpenGL version and platform
/// </summary>
public enum PixelFormat
{
/// <summary>
/// 8 bit per pixel (no alpha)
/// </summary>
PIXELFORMAT_UNCOMPRESSED_GRAYSCALE = 1,
/// <summary>
/// 8*2 bpp (2 channels)
/// </summary>
PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA,
/// <summary>
/// 16 bpp
/// </summary>
PIXELFORMAT_UNCOMPRESSED_R5G6B5,
/// <summary>
/// 24 bpp
/// </summary>
PIXELFORMAT_UNCOMPRESSED_R8G8B8,
/// <summary>
/// 16 bpp (1 bit alpha)
/// </summary>
PIXELFORMAT_UNCOMPRESSED_R5G5B5A1,
/// <summary>
/// 16 bpp (4 bit alpha)
/// </summary>
PIXELFORMAT_UNCOMPRESSED_R4G4B4A4,
/// <summary>
/// 32 bpp
/// </summary>
PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
/// <summary>
/// 32 bpp (1 channel - float)
/// </summary>
PIXELFORMAT_UNCOMPRESSED_R32,
/// <summary>
/// 32*3 bpp (3 channels - float)
/// </summary>
PIXELFORMAT_UNCOMPRESSED_R32G32B32,
/// <summary>
/// 32*4 bpp (4 channels - float)
/// </summary>
PIXELFORMAT_UNCOMPRESSED_R32G32B32A32,
/// <summary>
/// 4 bpp (no alpha)
/// </summary>
PIXELFORMAT_COMPRESSED_DXT1_RGB,
/// <summary>
/// 4 bpp (1 bit alpha)
/// </summary>
PIXELFORMAT_COMPRESSED_DXT1_RGBA,
/// <summary>
/// 8 bpp
/// </summary>
PIXELFORMAT_COMPRESSED_DXT3_RGBA,
/// <summary>
/// 8 bpp
/// </summary>
PIXELFORMAT_COMPRESSED_DXT5_RGBA,
/// <summary>
/// 4 bpp
/// </summary>
PIXELFORMAT_COMPRESSED_ETC1_RGB,
/// <summary>
/// 4 bpp
/// </summary>
PIXELFORMAT_COMPRESSED_ETC2_RGB,
/// <summary>
/// 8 bpp
/// </summary>
PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA,
/// <summary>
/// 4 bpp
/// </summary>
PIXELFORMAT_COMPRESSED_PVRT_RGB,
/// <summary>
/// 4 bpp
/// </summary>
PIXELFORMAT_COMPRESSED_PVRT_RGBA,
/// <summary>
/// 8 bpp
/// </summary>
PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA,
/// <summary>
/// 2 bpp
/// </summary>
PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA
}
/// <summary>
/// Image, pixel data stored in CPU memory (RAM)
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Image
{
/// <summary>
/// Image raw data
/// </summary>
public void* data;
/// <summary>
/// Image base width
/// </summary>
public int width;
/// <summary>
/// Image base height
/// </summary>
public int height;
/// <summary>
/// Mipmap levels, 1 by default
/// </summary>
public int mipmaps;
/// <summary>
/// Data format (PixelFormat type)
/// </summary>
public PixelFormat format;
}
}

492
Raylib-cs/types/Input.cs Normal file
View File

@ -0,0 +1,492 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// Keyboard keys (US keyboard layout)<br/>
/// NOTE: Use GetKeyPressed() to allow redefining required keys for alternative layouts
/// </summary>
public enum KeyboardKey
{
/// <summary>
/// NULL, used for no key pressed
/// </summary>
KEY_NULL = 0,
// Alphanumeric keys
KEY_APOSTROPHE = 39,
KEY_COMMA = 44,
KEY_MINUS = 45,
KEY_PERIOD = 46,
KEY_SLASH = 47,
KEY_ZERO = 48,
KEY_ONE = 49,
KEY_TWO = 50,
KEY_THREE = 51,
KEY_FOUR = 52,
KEY_FIVE = 53,
KEY_SIX = 54,
KEY_SEVEN = 55,
KEY_EIGHT = 56,
KEY_NINE = 57,
KEY_SEMICOLON = 59,
KEY_EQUAL = 61,
KEY_A = 65,
KEY_B = 66,
KEY_C = 67,
KEY_D = 68,
KEY_E = 69,
KEY_F = 70,
KEY_G = 71,
KEY_H = 72,
KEY_I = 73,
KEY_J = 74,
KEY_K = 75,
KEY_L = 76,
KEY_M = 77,
KEY_N = 78,
KEY_O = 79,
KEY_P = 80,
KEY_Q = 81,
KEY_R = 82,
KEY_S = 83,
KEY_T = 84,
KEY_U = 85,
KEY_V = 86,
KEY_W = 87,
KEY_X = 88,
KEY_Y = 89,
KEY_Z = 90,
// Function keys
KEY_SPACE = 32,
KEY_ESCAPE = 256,
KEY_ENTER = 257,
KEY_TAB = 258,
KEY_BACKSPACE = 259,
KEY_INSERT = 260,
KEY_DELETE = 261,
KEY_RIGHT = 262,
KEY_LEFT = 263,
KEY_DOWN = 264,
KEY_UP = 265,
KEY_PAGE_UP = 266,
KEY_PAGE_DOWN = 267,
KEY_HOME = 268,
KEY_END = 269,
KEY_CAPS_LOCK = 280,
KEY_SCROLL_LOCK = 281,
KEY_NUM_LOCK = 282,
KEY_PRINT_SCREEN = 283,
KEY_PAUSE = 284,
KEY_F1 = 290,
KEY_F2 = 291,
KEY_F3 = 292,
KEY_F4 = 293,
KEY_F5 = 294,
KEY_F6 = 295,
KEY_F7 = 296,
KEY_F8 = 297,
KEY_F9 = 298,
KEY_F10 = 299,
KEY_F11 = 300,
KEY_F12 = 301,
KEY_LEFT_SHIFT = 340,
KEY_LEFT_CONTROL = 341,
KEY_LEFT_ALT = 342,
KEY_LEFT_SUPER = 343,
KEY_RIGHT_SHIFT = 344,
KEY_RIGHT_CONTROL = 345,
KEY_RIGHT_ALT = 346,
KEY_RIGHT_SUPER = 347,
KEY_KB_MENU = 348,
KEY_LEFT_BRACKET = 91,
KEY_BACKSLASH = 92,
KEY_RIGHT_BRACKET = 93,
KEY_GRAVE = 96,
// Keypad keys
KEY_KP_0 = 320,
KEY_KP_1 = 321,
KEY_KP_2 = 322,
KEY_KP_3 = 323,
KEY_KP_4 = 324,
KEY_KP_5 = 325,
KEY_KP_6 = 326,
KEY_KP_7 = 327,
KEY_KP_8 = 328,
KEY_KP_9 = 329,
KEY_KP_DECIMAL = 330,
KEY_KP_DIVIDE = 331,
KEY_KP_MULTIPLY = 332,
KEY_KP_SUBTRACT = 333,
KEY_KP_ADD = 334,
KEY_KP_ENTER = 335,
KEY_KP_EQUAL = 336,
// Android key buttons
KEY_BACK = 4,
KEY_MENU = 82,
KEY_VOLUME_UP = 24,
KEY_VOLUME_DOWN = 25
}
/// <summary>
/// Mouse buttons
/// </summary>
public enum MouseButton
{
/// <summary>
/// Mouse button left
/// </summary>
MOUSE_BUTTON_LEFT = 0,
/// <summary>
/// Mouse button right
/// </summary>
MOUSE_BUTTON_RIGHT = 1,
/// <summary>
/// Mouse button middle (pressed wheel)
/// </summary>
MOUSE_BUTTON_MIDDLE = 2,
/// <summary>
/// Mouse button side (advanced mouse device)
/// </summary>
MOUSE_BUTTON_SIDE = 3,
/// <summary>
/// Mouse button extra (advanced mouse device)
/// </summary>
MOUSE_BUTTON_EXTRA = 4,
/// <summary>
/// Mouse button forward (advanced mouse device)
/// </summary>
MOUSE_BUTTON_FORWARD = 5,
/// <summary>
/// Mouse button back (advanced mouse device)
/// </summary>
MOUSE_BUTTON_BACK = 6,
MOUSE_LEFT_BUTTON = MOUSE_BUTTON_LEFT,
MOUSE_RIGHT_BUTTON = MOUSE_BUTTON_RIGHT,
MOUSE_MIDDLE_BUTTON = MOUSE_BUTTON_MIDDLE,
}
/// <summary>
/// Mouse cursor
/// </summary>
public enum MouseCursor
{
/// <summary>
/// Default pointer shape
/// </summary>
MOUSE_CURSOR_DEFAULT = 0,
/// <summary>
/// Arrow shape
/// </summary>
MOUSE_CURSOR_ARROW = 1,
/// <summary>
/// Text writing cursor shape
/// </summary>
MOUSE_CURSOR_IBEAM = 2,
/// <summary>
/// Cross shape
/// </summary>
MOUSE_CURSOR_CROSSHAIR = 3,
/// <summary>
/// Pointing hand cursor
/// </summary>
MOUSE_CURSOR_POINTING_HAND = 4,
/// <summary>
/// Horizontal resize/move arrow shape
/// </summary>
MOUSE_CURSOR_RESIZE_EW = 5,
/// <summary>
/// Vertical resize/move arrow shape
/// </summary>
MOUSE_CURSOR_RESIZE_NS = 6,
/// <summary>
/// Top-left to bottom-right diagonal resize/move arrow shape
/// </summary>
MOUSE_CURSOR_RESIZE_NWSE = 7,
/// <summary>
/// The top-right to bottom-left diagonal resize/move arrow shape
/// </summary>
MOUSE_CURSOR_RESIZE_NESW = 8,
/// <summary>
/// The omni-directional resize/move cursor shape
/// </summary>
MOUSE_CURSOR_RESIZE_ALL = 9,
/// <summary>
/// The operation-not-allowed shape
/// </summary>
MOUSE_CURSOR_NOT_ALLOWED = 10
}
/// <summary>Gamepad axis</summary>
public enum GamepadAxis
{
/// <summary>
/// Gamepad left stick X axis
/// </summary>
GAMEPAD_AXIS_LEFT_X = 0,
/// <summary>
/// Gamepad left stick Y axis
/// </summary>
GAMEPAD_AXIS_LEFT_Y = 1,
/// <summary>
/// Gamepad right stick X axis
/// </summary>
GAMEPAD_AXIS_RIGHT_X = 2,
/// <summary>
/// Gamepad right stick Y axis
/// </summary>
GAMEPAD_AXIS_RIGHT_Y = 3,
/// <summary>
/// Gamepad back trigger left, pressure level: [1..-1]
/// </summary>
GAMEPAD_AXIS_LEFT_TRIGGER = 4,
/// <summary>
/// Gamepad back trigger right, pressure level: [1..-1]
/// </summary>
GAMEPAD_AXIS_RIGHT_TRIGGER = 5
}
/// <summary>
/// Gamepad buttons
/// </summary>
public enum GamepadButton
{
/// <summary>
/// This is here just for error checking
/// </summary>
GAMEPAD_BUTTON_UNKNOWN = 0,
/// <summary>
/// Gamepad left DPAD up button
/// </summary>
GAMEPAD_BUTTON_LEFT_FACE_UP,
/// <summary>
/// Gamepad left DPAD right button
/// </summary>
GAMEPAD_BUTTON_LEFT_FACE_RIGHT,
/// <summary>
/// Gamepad left DPAD down button
/// </summary>
GAMEPAD_BUTTON_LEFT_FACE_DOWN,
/// <summary>
/// Gamepad left DPAD left button
/// </summary>
GAMEPAD_BUTTON_LEFT_FACE_LEFT,
/// <summary>
/// Gamepad right button up (i.e. PS3: Triangle, Xbox: Y)
/// </summary>
GAMEPAD_BUTTON_RIGHT_FACE_UP,
/// <summary>
/// Gamepad right button right (i.e. PS3: Square, Xbox: X)
/// </summary>
GAMEPAD_BUTTON_RIGHT_FACE_RIGHT,
/// <summary>
/// Gamepad right button down (i.e. PS3: Cross, Xbox: A)
/// </summary>
GAMEPAD_BUTTON_RIGHT_FACE_DOWN,
/// <summary>
/// Gamepad right button left (i.e. PS3: Circle, Xbox: B)
/// </summary>
GAMEPAD_BUTTON_RIGHT_FACE_LEFT,
// Triggers
GAMEPAD_BUTTON_LEFT_TRIGGER_1,
GAMEPAD_BUTTON_LEFT_TRIGGER_2,
GAMEPAD_BUTTON_RIGHT_TRIGGER_1,
GAMEPAD_BUTTON_RIGHT_TRIGGER_2,
// These are buttons in the center of the gamepad
/// <summary>
/// PS3 Select
/// </summary>
GAMEPAD_BUTTON_MIDDLE_LEFT,
/// <summary>
/// PS Button/XBOX Button
/// </summary>
GAMEPAD_BUTTON_MIDDLE,
/// <summary>
/// PS3 Start
/// </summary>
GAMEPAD_BUTTON_MIDDLE_RIGHT,
/// <summary>
/// Left joystick press button
/// </summary>
GAMEPAD_BUTTON_LEFT_THUMB,
/// <summary>
/// Right joystick press button
/// </summary>
GAMEPAD_BUTTON_RIGHT_THUMB
}
/// <summary>Gesture
/// NOTE: It could be used as flags to enable only some gestures
/// </summary>
[Flags]
public enum Gesture : uint
{
GESTURE_NONE = 0,
GESTURE_TAP = 1,
GESTURE_DOUBLETAP = 2,
GESTURE_HOLD = 4,
GESTURE_DRAG = 8,
GESTURE_SWIPE_RIGHT = 16,
GESTURE_SWIPE_LEFT = 32,
GESTURE_SWIPE_UP = 64,
GESTURE_SWIPE_DOWN = 128,
GESTURE_PINCH_IN = 256,
GESTURE_PINCH_OUT = 512
}
/// <summary>
/// Head-Mounted-Display device parameters
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct VrDeviceInfo
{
/// <summary>
/// HMD horizontal resolution in pixels
/// </summary>
public int hResolution;
/// <summary>
/// HMD vertical resolution in pixels
/// </summary>
public int vResolution;
/// <summary>
/// HMD horizontal size in meters
/// </summary>
public float hScreenSize;
/// <summary>
/// HMD vertical size in meters
/// </summary>
public float vScreenSize;
/// <summary>
/// HMD screen center in meters
/// </summary>
public float vScreenCenter;
/// <summary>
/// HMD distance between eye and display in meters
/// </summary>
public float eyeToScreenDistance;
/// <summary>
/// HMD lens separation distance in meters
/// </summary>
public float lensSeparationDistance;
/// <summary>
/// HMD IPD (distance between pupils) in meters
/// </summary>
public float interpupillaryDistance;
/// <summary>
/// HMD lens distortion constant parameters
/// </summary>
public fixed float lensDistortionValues[4];
/// <summary>
/// HMD chromatic aberration correction parameters
/// </summary>
public fixed float chromaAbCorrection[4];
}
/// <summary>
/// VR Stereo rendering configuration for simulator
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct VrStereoConfig
{
/// <summary>
/// VR projection matrices (per eye)
/// </summary>
public Matrix4x4 projection1;
/// <summary>
/// VR projection matrices (per eye)
/// </summary>
public Matrix4x4 projection2;
/// <summary>
/// VR view offset matrices (per eye)
/// </summary>
public Matrix4x4 viewOffset1;
/// <summary>
/// VR view offset matrices (per eye)
/// </summary>
public Matrix4x4 viewOffset2;
/// <summary>
/// VR left lens center
/// </summary>
public Vector2 leftLensCenter;
/// <summary>
/// VR right lens center
/// </summary>
public Vector2 rightLensCenter;
/// <summary>
/// VR left screen center
/// </summary>
public Vector2 leftScreenCenter;
/// <summary>
/// VR right screen center
/// </summary>
public Vector2 rightScreenCenter;
/// <summary>
/// VR distortion scale
/// </summary>
public Vector2 scale;
/// <summary>
/// VR distortion scale in
/// </summary>
public Vector2 scaleIn;
}
}

166
Raylib-cs/types/Logging.cs Normal file
View File

@ -0,0 +1,166 @@
using System;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
internal readonly struct Native
{
internal const string Msvcrt = "msvcrt";
internal const string Libc = "libc";
internal const string LibSystem = "libSystem";
[DllImport(LibSystem, EntryPoint = "vasprintf", CallingConvention = CallingConvention.Cdecl)]
public static extern int vasprintf_apple(ref IntPtr buffer, IntPtr format, IntPtr args);
[DllImport(Libc, EntryPoint = "vsprintf", CallingConvention = CallingConvention.Cdecl)]
public static extern int vsprintf_linux(IntPtr buffer, IntPtr format, IntPtr args);
[DllImport(Msvcrt, EntryPoint = "vsprintf", CallingConvention = CallingConvention.Cdecl)]
public static extern int vsprintf_windows(IntPtr buffer, IntPtr format, IntPtr args);
[DllImport(Libc, EntryPoint = "vsnprintf", CallingConvention = CallingConvention.Cdecl)]
public static extern int vsnprintf_linux(IntPtr buffer, UIntPtr size, IntPtr format, IntPtr args);
[DllImport(Msvcrt, EntryPoint = "vsnprintf", CallingConvention = CallingConvention.Cdecl)]
public static extern int vsnprintf_windows(IntPtr buffer, UIntPtr size, IntPtr format, IntPtr args);
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
struct VaListLinuxX64
{
uint gpOffset;
uint fpOffset;
IntPtr overflowArgArea;
IntPtr regSaveArea;
}
/// <summary>
/// Logging workaround for formatting strings from native code
/// </summary>
public static unsafe class Logging
{
static Logging()
{
Raylib.SetTraceLogCallback(&LogConsole);
}
[UnmanagedCallersOnly(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
public static unsafe void LogConsole(int msgType, sbyte* text, sbyte* args)
{
var message = GetLogMessage(new IntPtr(text), new IntPtr(args));
Console.WriteLine(message);
}
public static string GetLogMessage(IntPtr format, IntPtr args)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return AppleLogCallback(format, args);
}
// Special marshalling is needed on Linux desktop 64 bits.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && IntPtr.Size == 8)
{
return LinuxX64LogCallback(format, args);
}
var byteLength = vsnprintf(IntPtr.Zero, UIntPtr.Zero, format, args) + 1;
if (byteLength <= 1)
{
return string.Empty;
}
var buffer = Marshal.AllocHGlobal(byteLength);
vsprintf(buffer, format, args);
string result = Marshal.PtrToStringUTF8(buffer);
Marshal.FreeHGlobal(buffer);
return result;
}
static string AppleLogCallback(IntPtr format, IntPtr args)
{
IntPtr buffer = IntPtr.Zero;
try
{
var count = Native.vasprintf_apple(ref buffer, format, args);
if (count == -1)
{
return string.Empty;
}
return Marshal.PtrToStringUTF8(buffer) ?? string.Empty;
}
finally
{
Marshal.FreeHGlobal(buffer);
}
}
static string LinuxX64LogCallback(IntPtr format, IntPtr args)
{
// The args pointer cannot be reused between two calls. We need to make a copy of the underlying structure.
var listStructure = Marshal.PtrToStructure<VaListLinuxX64>(args);
IntPtr listPointer = IntPtr.Zero;
int byteLength = 0;
string result = "";
// Get length of args
listPointer = Marshal.AllocHGlobal(Marshal.SizeOf(listStructure));
Marshal.StructureToPtr(listStructure, listPointer, false);
byteLength = Native.vsnprintf_linux(IntPtr.Zero, UIntPtr.Zero, format, listPointer) + 1;
// Allocate buffer for result
Marshal.StructureToPtr(listStructure, listPointer, false);
IntPtr utf8Buffer = IntPtr.Zero;
utf8Buffer = Marshal.AllocHGlobal(byteLength);
// Print result into buffer
Native.vsprintf_linux(utf8Buffer, format, listPointer);
result = Marshal.PtrToStringUTF8(utf8Buffer);
Marshal.FreeHGlobal(listPointer);
Marshal.FreeHGlobal(utf8Buffer);
return result;
}
// https://github.com/dotnet/runtime/issues/51052
static int vsnprintf(IntPtr buffer, UIntPtr size, IntPtr format, IntPtr args)
{
var os = Environment.OSVersion;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return Native.vsnprintf_windows(buffer, size, format, args);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return Native.vsnprintf_linux(buffer, size, format, args);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID")))
{
return Native.vsprintf_linux(buffer, format, args);
}
return -1;
}
// https://github.com/dotnet/runtime/issues/51052
static int vsprintf(IntPtr buffer, IntPtr format, IntPtr args)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return Native.vsprintf_windows(buffer, format, args);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return Native.vsprintf_linux(buffer, format, args);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID")))
{
return Native.vsprintf_linux(buffer, format, args);
}
return -1;
}
}
}

View File

@ -0,0 +1,92 @@
using System;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// Material map index
/// </summary>
public enum MaterialMapIndex
{
/// <summary>
/// NOTE: Same as MATERIAL_MAP_DIFFUSE
/// </summary>
MATERIAL_MAP_ALBEDO = 0,
/// <summary>
/// NOTE: Same as MATERIAL_MAP_SPECULAR
/// </summary>
MATERIAL_MAP_METALNESS,
MATERIAL_MAP_NORMAL,
MATERIAL_MAP_ROUGHNESS,
MATERIAL_MAP_OCCLUSION,
MATERIAL_MAP_EMISSION,
MATERIAL_MAP_HEIGHT,
/// <summary>
/// NOTE: Uses GL_TEXTURE_CUBE_MAP
/// </summary>
MATERIAL_MAP_CUBEMAP,
/// <summary>
/// NOTE: Uses GL_TEXTURE_CUBE_MAP
/// </summary>
MATERIAL_MAP_IRRADIANCE,
/// <summary>
/// NOTE: Uses GL_TEXTURE_CUBE_MAP
/// </summary>
MATERIAL_MAP_PREFILTER,
MATERIAL_MAP_BRDF,
MATERIAL_MAP_DIFFUSE = MATERIAL_MAP_ALBEDO,
MATERIAL_MAP_SPECULAR = MATERIAL_MAP_METALNESS,
}
/// <summary>
/// Material texture map
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct MaterialMap
{
/// <summary>
/// Material map texture
/// </summary>
public Texture2D texture;
/// <summary>
/// Material map color
/// </summary>
public Color color;
/// <summary>
/// Material map value
/// </summary>
public float value;
}
/// <summary>
/// Material type (generic)
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Material
{
/// <summary>
/// Material shader
/// </summary>
public Shader shader;
//TODO: convert
/// <summary>
/// Material maps
/// </summary>
public MaterialMap* maps;
/// <summary>
/// Material generic parameters (if required)
/// </summary>
public fixed float param[4];
}
}

101
Raylib-cs/types/Mesh.cs Normal file
View File

@ -0,0 +1,101 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// Vertex data definning a mesh<br/>
/// NOTE: Data stored in CPU memory (and GPU)
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Mesh
{
/// <summary>
/// Number of vertices stored in arrays
/// </summary>
public int vertexCount;
/// <summary>
/// Number of triangles stored (indexed or not)
/// </summary>
public int triangleCount;
#region Default vertex data
/// <summary>
/// Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
/// </summary>
public float* vertices;
/// <summary>
/// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
/// </summary>
public float* texcoords;
/// <summary>
/// Vertex second texture coordinates (useful for lightmaps) (shader-location = 5)
/// </summary>
public float* texcoords2;
/// <summary>
/// Vertex normals (XYZ - 3 components per vertex) (shader-location = 2)
/// </summary>
public float* normals;
/// <summary>
/// Vertex tangents (XYZW - 4 components per vertex) (shader-location = 4)
/// </summary>
public float* tangents;
/// <summary>
/// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
/// </summary>
public byte* colors;
/// <summary>
/// Vertex indices (in case vertex data comes indexed)
/// </summary>
public ushort* indices;
#endregion
#region Animation vertex data
/// <summary>
/// Animated vertex positions (after bones transformations)
/// </summary>
public float* animVertices;
/// <summary>
/// Animated normals (after bones transformations)
/// </summary>
public float* animNormals;
/// <summary>
/// Vertex bone ids, up to 4 bones influence by vertex (skinning)
/// </summary>
public byte* boneIds;
/// <summary>
/// Vertex bone weight, up to 4 bones influence by vertex (skinning)
/// </summary>
public float* boneWeights;
#endregion
#region OpenGL identifiers
/// <summary>
/// OpenGL Vertex Array Object id
/// </summary>
public uint vaoId;
/// <summary>
/// OpenGL Vertex Buffer Objects id (default vertex data, uint[])
/// </summary>
public uint* vboId;
#endregion
}
}

151
Raylib-cs/types/Model.cs Normal file
View File

@ -0,0 +1,151 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// Bone information
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct BoneInfo
{
/// <summary>
/// Bone name (char[32])
/// </summary>
public fixed sbyte name[32];
/// <summary>
/// Bone parent
/// </summary>
public int parent;
}
/// <summary>
/// Model type
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Model
{
/// <summary>
/// Local transform matrix
/// </summary>
public Matrix4x4 transform;
/// <summary>
/// Number of meshes
/// </summary>
public int meshCount;
/// <summary>
/// Number of materials
/// </summary>
public int materialCount;
/// <summary>
/// Meshes array (Mesh *)
/// </summary>
public Mesh* meshes;
/// <summary>
/// Materials array (Material *)
/// </summary>
public Material* materials;
/// <summary>
/// Mesh material number (int *)
/// </summary>
public int* meshMaterial;
/// <summary>
/// Number of bones
/// </summary>
public int boneCount;
//TODO: Span
/// <summary>
/// Bones information (skeleton, BoneInfo *)
/// </summary>
public BoneInfo* bones;
//TODO: Span
/// <summary>
/// Bones base transformation (pose, Transform *)
/// </summary>
public Transform* bindPose;
}
/// <summary>
/// Model animation
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public readonly unsafe partial struct ModelAnimation
{
/// <summary>
/// Number of bones
/// </summary>
public readonly int boneCount;
/// <summary>
/// Number of animation frames
/// </summary>
public readonly int frameCount;
/// <summary>
/// Bones information (skeleton, BoneInfo *)
/// </summary>
public readonly BoneInfo* bones;
/// <inheritdoc cref="bones"/>
public ReadOnlySpan<BoneInfo> BoneInfo => new(bones, boneCount);
/// <summary>
/// Poses array by frame (Transform **)
/// </summary>
public readonly Transform** framePoses;
/// <inheritdoc cref="framePoses"/>
public FramePosesCollection FramePoses => new(framePoses, frameCount, boneCount);
public struct FramePosesCollection
{
readonly Transform** framePoses;
readonly int frameCount;
readonly int boneCount;
public FramePoses this[int index] => new(framePoses[index], boneCount);
public Transform this[int index1, int index2] => new FramePoses(framePoses[index1], boneCount)[index2];
internal FramePosesCollection(Transform** framePoses, int frameCount, int boneCount)
{
this.framePoses = framePoses;
this.frameCount = frameCount;
this.boneCount = boneCount;
}
}
}
public unsafe struct FramePoses
{
readonly Transform* poses;
readonly int count;
public ref Transform this[int index]
{
get
{
return ref poses[index];
}
}
internal FramePoses(Transform* poses, int count)
{
this.poses = poses;
this.count = count;
}
}
}

View File

@ -0,0 +1,62 @@
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// N-patch layout
/// </summary>
public enum NPatchLayout
{
/// <summary>
/// Npatch defined by 3x3 tiles
/// </summary>
NPATCH_NINE_PATCH = 0,
/// <summary>
/// Npatch defined by 1x3 tiles
/// </summary>
NPATCH_THREE_PATCH_VERTICAL,
/// <summary>
/// Npatch defined by 3x1 tiles
/// </summary>
NPATCH_THREE_PATCH_HORIZONTAL
}
/// <summary>
/// N-Patch layout info
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct NPatchInfo
{
/// <summary>
/// Texture source rectangle
/// </summary>
public Rectangle source;
/// <summary>
/// Left border offset
/// </summary>
public int left;
/// <summary>
/// Top border offset
/// </summary>
public int top;
/// <summary>
/// Right border offset
/// </summary>
public int right;
/// <summary>
/// Bottom border offset
/// </summary>
public int bottom;
/// <summary>
/// Layout of the n-patch: 3x3, 1x3 or 3x1
/// </summary>
public NPatchLayout layout;
}
}

55
Raylib-cs/types/Ray.cs Normal file
View File

@ -0,0 +1,55 @@
using System.Numerics;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// Ray, ray for raycasting
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct Ray
{
/// <summary>
/// Ray position (origin)
/// </summary>
public Vector3 position;
/// <summary>
/// Ray direction
/// </summary>
public Vector3 direction;
public Ray(Vector3 position, Vector3 direction)
{
this.position = position;
this.direction = direction;
}
}
/// <summary>
/// Raycast hit information
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct RayCollision
{
/// <summary>
/// Did the ray hit something?
/// </summary>
public CBool hit;
/// <summary>
/// Distance to nearest hit
/// </summary>
public float distance;
/// <summary>
/// Position of nearest hit
/// </summary>
public Vector3 point;
/// <summary>
/// Surface normal of hit
/// </summary>
public Vector3 normal;
}
}

View File

@ -0,0 +1,929 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
public static unsafe partial class Raylib
{
/// <summary>Initialize window and OpenGL context</summary>
public static void InitWindow(int width, int height, string title)
{
using var str1 = title.ToUTF8Buffer();
InitWindow(width, height, str1.AsPointer());
}
/// <summary>Set title for window (only PLATFORM_DESKTOP)</summary>
public static void SetWindowTitle(string title)
{
using var str1 = title.ToUTF8Buffer();
SetWindowTitle(str1.AsPointer());
}
/// <summary>Get the human-readable, UTF-8 encoded name of the primary monitor</summary>
public static string GetMonitorName_(int monitor)
{
return Utf8StringUtils.GetUTF8String(GetMonitorName(monitor));
}
/// <summary>Get clipboard text content</summary>
public static string GetClipboardText_()
{
return Utf8StringUtils.GetUTF8String(GetClipboardText());
}
/// <summary>Set clipboard text content</summary>
public static void SetClipboardText(string text)
{
using var str1 = text.ToUTF8Buffer();
SetClipboardText(str1.AsPointer());
}
/// <summary>Load shader from files and bind default locations</summary>
public static Shader LoadShader(string vsFileName, string fsFileName)
{
using var str1 = vsFileName.ToUTF8Buffer();
using var str2 = fsFileName.ToUTF8Buffer();
return LoadShader(str1.AsPointer(), str2.AsPointer());
}
/// <summary>Load shader from code string and bind default locations</summary>
public static Shader LoadShaderFromMemory(string vsCode, string fsCode)
{
using var str1 = vsCode.ToUTF8Buffer();
using var str2 = fsCode.ToUTF8Buffer();
return LoadShaderFromMemory(str1.AsPointer(), str2.AsPointer());
}
/// <summary>Get shader uniform location</summary>
public static int GetShaderLocation(Shader shader, string uniformName)
{
using var str1 = uniformName.ToUTF8Buffer();
return GetShaderLocation(shader, str1.AsPointer());
}
/// <summary>Get shader attribute location</summary>
public static int GetShaderLocationAttrib(Shader shader, string attribName)
{
using var str1 = attribName.ToUTF8Buffer();
return GetShaderLocationAttrib(shader, str1.AsPointer());
}
/// <summary>Takes a screenshot of current screen (saved a .png)</summary>
public static void TakeScreenshot(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
TakeScreenshot(str1.AsPointer());
}
/// <summary>Check file extension</summary>
public static CBool IsFileExtension(string fileName, string ext)
{
using var str1 = fileName.ToUTF8Buffer();
using var str2 = ext.ToUTF8Buffer();
return IsFileExtension(str1.AsPointer(), str2.AsPointer());
}
/// <summary>Get file modification time (last write time)</summary>
public static long GetFileModTime(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
return GetFileModTime(str1.AsPointer());
}
/// <summary>Load image from file into CPU memory (RAM)</summary>
public static Image LoadImage(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadImage(str1.AsPointer());
}
/// <summary>Load image from RAW file data</summary>
public static Image LoadImageRaw(string fileName, int width, int height, PixelFormat format, int headerSize)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadImageRaw(str1.AsPointer(), width, height, format, headerSize);
}
/// <summary>Load image sequence from file (frames appended to image.data)</summary>
public static Image LoadImageAnim(string fileName, int[] frames)
{
using var str1 = fileName.ToUTF8Buffer();
fixed (int* p = frames)
{
return LoadImageAnim(str1.AsPointer(), p);
}
}
/// <summary>Export image data to file</summary>
public static void ExportImage(Image image, string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
ExportImage(image, str1.AsPointer());
}
/// <summary>Export image as code file defining an array of bytes</summary>
public static void ExportImageAsCode(Image image, string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
ExportImageAsCode(image, str1.AsPointer());
}
/// <summary>Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR)</summary>
public static void TraceLog(TraceLogLevel logLevel, string text)
{
using var str1 = text.ToUTF8Buffer();
TraceLog(logLevel, str1.AsPointer());
}
/// <summary>Set shader uniform value vector</summary>
public static void SetShaderValueV<T>(Shader shader, int uniformLoc, T[] values, ShaderUniformDataType uniformType, int count)
where T : unmanaged
{
SetShaderValueV(shader, uniformLoc, (Span<T>)values, uniformType, count);
}
/// <summary>Set shader uniform value vector</summary>
public static void SetShaderValueV<T>(Shader shader, int uniformLoc, Span<T> values, ShaderUniformDataType uniformType, int count)
where T : unmanaged
{
fixed (T* valuePtr = values)
{
SetShaderValueV(shader, uniformLoc, valuePtr, uniformType, count);
}
}
/// <summary>Set shader uniform value</summary>
public static void SetShaderValue<T>(Shader shader, int uniformLoc, T value, ShaderUniformDataType uniformType)
where T : unmanaged
{
SetShaderValue(shader, uniformLoc, &value, uniformType);
}
/// <summary>Set shader uniform value</summary>
public static void SetShaderValue<T>(Shader shader, int uniformLoc, T[] values, ShaderUniformDataType uniformType)
where T : unmanaged
{
SetShaderValue(shader, uniformLoc, (Span<T>)values, uniformType);
}
/// <summary>Set shader uniform value</summary>
public static void SetShaderValue<T>(Shader shader, int uniformLoc, Span<T> values, ShaderUniformDataType uniformType)
where T : unmanaged
{
fixed (T* valuePtr = values)
{
SetShaderValue(shader, uniformLoc, valuePtr, uniformType);
}
}
/// <summary>Load file data as byte array (read)</summary>
public static byte* LoadFileData(string fileName, ref uint bytesRead)
{
using var str1 = fileName.ToUTF8Buffer();
fixed (uint* p = &bytesRead)
{
return LoadFileData(str1.AsPointer(), p);
}
}
/// <summary>Get dropped files names (memory should be freed)</summary>
public static string[] GetDroppedFiles()
{
int count;
var buffer = GetDroppedFiles(&count);
var files = new string[count];
for (var i = 0; i < count; i++)
{
files[i] = Marshal.PtrToStringUTF8((IntPtr)buffer[i]);
}
return files;
}
/// <summary>Return gamepad internal name id</summary>
public static string GetGamepadName_(int gamepad)
{
return Utf8StringUtils.GetUTF8String(GetGamepadName(gamepad));
}
/// <summary>Update camera position for selected mode</summary>
public static void UpdateCamera(ref Camera3D camera)
{
fixed (Camera3D* c = &camera)
{
UpdateCamera(c);
}
}
/// <summary>Check the collision between two lines defined by two points each, returns collision point by reference</summary>
public static CBool CheckCollisionLines(Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2, ref Vector2 collisionPoint)
{
fixed (Vector2* p = &collisionPoint)
{
return CheckCollisionLines(startPos1, endPos1, startPos2, endPos2, p);
}
}
/// <summary>Create an image from text (default font)</summary>
public static Image ImageText(string text, int fontSize, Color color)
{
using var str1 = text.ToUTF8Buffer();
return ImageText(str1.AsPointer(), fontSize, color);
}
/// <summary>Create an image from text (custom sprite font)</summary>
public static Image ImageTextEx(Font font, string text, float fontSize, float spacing, Color tint)
{
using var str1 = text.ToUTF8Buffer();
return ImageTextEx(font, str1.AsPointer(), fontSize, spacing, tint);
}
/// <summary>Convert image to POT (power-of-two)</summary>
public static void ImageToPOT(ref Image image, Color fill)
{
fixed (Image* p = &image)
{
ImageToPOT(p, fill);
}
}
/// <summary>Convert image data to desired format</summary>
public static void ImageFormat(ref Image image, PixelFormat newFormat)
{
fixed (Image* p = &image)
{
ImageFormat(p, newFormat);
}
}
/// <summary>Apply alpha mask to image</summary>
public static void ImageAlphaMask(ref Image image, Image alphaMask)
{
fixed (Image* p = &image)
{
ImageAlphaMask(p, alphaMask);
}
}
/// <summary>Clear alpha channel to desired color</summary>
public static void ImageAlphaClear(ref Image image, Color color, float threshold)
{
fixed (Image* p = &image)
{
ImageAlphaClear(p, color, threshold);
}
}
/// <summary>Crop image depending on alpha value</summary>
public static void ImageAlphaCrop(ref Image image, float threshold)
{
fixed (Image* p = &image)
{
ImageAlphaCrop(p, threshold);
}
}
/// <summary>Premultiply alpha channel</summary>
public static void ImageAlphaPremultiply(ref Image image)
{
fixed (Image* p = &image)
{
ImageAlphaPremultiply(p);
}
}
/// <summary>Crop an image to a defined rectangle</summary>
public static void ImageCrop(ref Image image, Rectangle crop)
{
fixed (Image* p = &image)
{
ImageCrop(p, crop);
}
}
/// <summary>Resize image (Bicubic scaling algorithm)</summary>
public static void ImageResize(ref Image image, int newWidth, int newHeight)
{
fixed (Image* p = &image)
{
ImageResize(p, newWidth, newHeight);
}
}
/// <summary>Resize image (Nearest-Neighbor scaling algorithm)</summary>
public static void ImageResizeNN(ref Image image, int newWidth, int newHeight)
{
fixed (Image* p = &image)
{
ImageResizeNN(p, newWidth, newHeight);
}
}
/// <summary>Resize canvas and fill with color</summary>
public static void ImageResizeCanvas(ref Image image, int newWidth, int newHeight, int offsetX, int offsetY, Color color)
{
fixed (Image* p = &image)
{
ImageResizeCanvas(p, newWidth, newHeight, offsetX, offsetY, color);
}
}
/// <summary>Generate all mipmap levels for a provided image</summary>
public static void ImageMipmaps(ref Image image)
{
fixed (Image* p = &image)
{
ImageMipmaps(p);
}
}
/// <summary>Dither image data to 16bpp or lower (Floyd-Steinberg dithering)</summary>
public static void ImageDither(ref Image image, int rBpp, int gBpp, int bBpp, int aBpp)
{
fixed (Image* p = &image)
{
ImageDither(p, rBpp, gBpp, bBpp, aBpp);
}
}
/// <summary>Flip image vertically</summary>
public static void ImageFlipVertical(ref Image image)
{
fixed (Image* p = &image)
{
ImageFlipVertical(p);
}
}
/// <summary>Flip image horizontally</summary>
public static void ImageFlipHorizontal(ref Image image)
{
fixed (Image* p = &image)
{
ImageFlipHorizontal(p);
}
}
/// <summary>Rotate image clockwise 90deg</summary>
public static void ImageRotateCW(ref Image image)
{
fixed (Image* p = &image)
{
ImageRotateCW(p);
}
}
/// <summary>Rotate image counter-clockwise 90deg</summary>
public static void ImageRotateCCW(ref Image image)
{
fixed (Image* p = &image)
{
ImageRotateCCW(p);
}
}
/// <summary>Modify image color: tint</summary>
public static void ImageColorTint(ref Image image, Color color)
{
fixed (Image* p = &image)
{
ImageColorTint(p, color);
}
}
/// <summary>Modify image color: invert</summary>
public static void ImageColorInvert(ref Image image)
{
fixed (Image* p = &image)
{
ImageColorInvert(p);
}
}
/// <summary>Modify image color: grayscale</summary>
public static void ImageColorGrayscale(ref Image image)
{
fixed (Image* p = &image)
{
ImageColorGrayscale(p);
}
}
/// <summary>Modify image color: contrast (-100 to 100)</summary>
public static void ImageColorContrast(ref Image image, float contrast)
{
fixed (Image* p = &image)
{
ImageColorContrast(p, contrast);
}
}
/// <summary>Modify image color: brightness (-255 to 255)</summary>
public static void ImageColorBrightness(ref Image image, int brightness)
{
fixed (Image* p = &image)
{
ImageColorBrightness(p, brightness);
}
}
/// <summary>Modify image color: replace color</summary>
public static void ImageColorReplace(ref Image image, Color color, Color replace)
{
fixed (Image* p = &image)
{
ImageColorReplace(p, color, replace);
}
}
/// <summary>Clear image background with given color</summary>
public static void ImageClearBackground(ref Image dst, Color color)
{
fixed (Image* p = &dst)
{
ImageClearBackground(p, color);
}
}
/// <summary>Draw pixel within an image</summary>
public static void ImageDrawPixel(ref Image dst, int posX, int posY, Color color)
{
fixed (Image* p = &dst)
{
ImageDrawPixel(p, posX, posY, color);
}
}
/// <summary>Draw pixel within an image (Vector version)</summary>
public static void ImageDrawPixelV(ref Image dst, Vector2 position, Color color)
{
fixed (Image* p = &dst)
{
ImageDrawPixelV(p, position, color);
}
}
/// <summary>Draw line within an image</summary>
public static void ImageDrawLine(ref Image dst, int startPosX, int startPosY, int endPosX, int endPosY, Color color)
{
fixed (Image* p = &dst)
{
ImageDrawLine(p, startPosX, startPosY, endPosX, endPosY, color);
}
}
/// <summary>Draw line within an image (Vector version)</summary>
public static void ImageDrawLineV(ref Image dst, Vector2 start, Vector2 end, Color color)
{
fixed (Image* p = &dst)
{
ImageDrawLineV(p, start, end, color);
}
}
/// <summary>Draw circle within an image</summary>
public static void ImageDrawCircle(ref Image dst, int centerX, int centerY, int radius, Color color)
{
fixed (Image* p = &dst)
{
ImageDrawCircle(p, centerX, centerY, radius, color);
}
}
/// <summary>Draw circle within an image (Vector version)</summary>
public static void ImageDrawCircleV(ref Image dst, Vector2 center, int radius, Color color)
{
fixed (Image* p = &dst)
{
ImageDrawCircleV(p, center, radius, color);
}
}
/// <summary>Draw rectangle within an image</summary>
public static void ImageDrawRectangle(ref Image dst, int posX, int posY, int width, int height, Color color)
{
fixed (Image* p = &dst)
{
ImageDrawRectangle(p, posX, posY, width, height, color);
}
}
/// <summary>Draw rectangle within an image (Vector version)</summary>
public static void ImageDrawRectangleV(ref Image dst, Vector2 position, Vector2 size, Color color)
{
fixed (Image* p = &dst)
{
ImageDrawRectangleV(p, position, size, color);
}
}
/// <summary>Draw rectangle within an image</summary>
public static void ImageDrawRectangleRec(ref Image dst, Rectangle rec, Color color)
{
fixed (Image* p = &dst)
{
ImageDrawRectangleRec(p, rec, color);
}
}
/// <summary>Draw rectangle lines within an image</summary>
public static void ImageDrawRectangleLines(ref Image dst, Rectangle rec, int thick, Color color)
{
fixed (Image* p = &dst)
{
ImageDrawRectangleLines(p, rec, thick, color);
}
}
/// <summary>Draw a source image within a destination image (tint applied to source)</summary>
public static void ImageDraw(ref Image dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint)
{
fixed (Image* p = &dst)
{
ImageDraw(p, src, srcRec, dstRec, tint);
}
}
/// <summary>Draw text (using default font) within an image (destination)</summary>
public static void ImageDrawText(ref Image dst, string text, int x, int y, int fontSize, Color color)
{
using var str1 = text.ToUTF8Buffer();
fixed (Image* p = &dst)
{
ImageDrawText(p, str1.AsPointer(), x, y, fontSize, color);
}
}
/// <summary>Draw text (custom sprite font) within an image (destination)</summary>
public static void ImageDrawTextEx(ref Image dst, Font font, string text, Vector2 position, int fontSize, float spacing, Color color)
{
using var str1 = text.ToUTF8Buffer();
fixed (Image* p = &dst)
{
ImageDrawTextEx(p, font, str1.AsPointer(), position, fontSize, spacing, color);
}
}
/// <summary>Load texture from file into GPU memory (VRAM)</summary>
public static Texture2D LoadTexture(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadTexture(str1.AsPointer());
}
/// <summary>Generate GPU mipmaps for a texture</summary>
public static void GenTextureMipmaps(ref Texture2D texture)
{
fixed (Texture2D* p = &texture)
{
GenTextureMipmaps(p);
}
}
/// <summary>Load font from file into GPU memory (VRAM)</summary>
public static Font LoadFont(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadFont(str1.AsPointer());
}
/// <summary>Load font from file with extended parameters</summary>
public static Font LoadFontEx(string fileName, int fontSize, int[] fontChars, int charsCount)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadFontEx(str1.AsPointer(), fontSize, fontChars, charsCount);
}
/// <summary>Upload vertex data into GPU and provided VAO/VBO ids</summary>
public static void UploadMesh(ref Mesh mesh, CBool dynamic)
{
fixed (Mesh* p = &mesh)
{
UploadMesh(p, dynamic);
}
}
/// <summary>Unload mesh from memory (RAM and/or VRAM)</summary>
public static void UnloadMesh(ref Mesh mesh)
{
fixed (Mesh* p = &mesh)
{
UnloadMesh(p);
}
}
/// <summary>Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...)</summary>
public static void SetMaterialTexture(ref Material material, MaterialMapIndex mapType, Texture2D texture)
{
fixed (Material* p = &material)
{
SetMaterialTexture(p, mapType, texture);
}
}
/// <summary>Set material for a mesh</summary>
public static void SetModelMeshMaterial(ref Model model, int meshId, int materialId)
{
fixed (Model* p = &model)
{
SetModelMeshMaterial(p, meshId, materialId);
}
}
/// <summary>Load model animations from file</summary>
public static ReadOnlySpan<ModelAnimation> LoadModelAnimations(string fileName, ref uint animsCount)
{
using var str1 = fileName.ToUTF8Buffer();
fixed (uint* p = &animsCount)
{
var model = LoadModelAnimations(str1.AsPointer(), p);
if ((IntPtr)model == IntPtr.Zero)
{
throw new ApplicationException("Failed to load animation");
}
return new ReadOnlySpan<ModelAnimation>(model, (int)animsCount);
}
}
/// <summary>Compute mesh tangents</summary>
public static void GenMeshTangents(ref Mesh mesh)
{
fixed (Mesh* p = &mesh)
{
GenMeshTangents(p);
}
}
/// <summary>Compute mesh binormals</summary>
public static void GenMeshBinormals(ref Mesh mesh)
{
fixed (Mesh* p = &mesh)
{
GenMeshBinormals(p);
}
}
/// <summary>Convert wave data to desired format</summary>
public static void WaveFormat(ref Wave wave, int sampleRate, int sampleSize, int channels)
{
fixed (Wave* p = &wave)
{
WaveFormat(p, sampleRate, sampleSize, channels);
}
}
/// <summary>Crop a wave to defined samples range</summary>
public static void WaveCrop(ref Wave wave, int initSample, int finalSample)
{
fixed (Wave* p = &wave)
{
WaveCrop(p, initSample, finalSample);
}
}
/// <summary>Draw lines sequence</summary>
public static void DrawLineStrip(Vector2[] points, int numPoints, Color color)
{
fixed (Vector2* p = points)
{
DrawLineStrip(p, numPoints, color);
}
}
/// <summary>Draw a triangle fan defined by points (first vertex is the center)</summary>
public static void DrawTriangleFan(Vector2[] points, int numPoints, Color color)
{
fixed (Vector2* p = points)
{
DrawTriangleFan(p, numPoints, color);
}
}
/// <summary>Draw a triangle strip defined by points</summary>
public static void DrawTriangleStrip(Vector2[] points, int pointsCount, Color color)
{
fixed (Vector2* p = points)
{
DrawTriangleStrip(p, pointsCount, color);
}
}
/// <summary>Draw a textured polygon</summary>
public static void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2[] points, Vector2[] texcoords, int pointsCount, Color tint)
{
fixed (Vector2* p = points)
{
fixed (Vector2* p1 = texcoords)
{
DrawTexturePoly(texture, center, p, p1, pointsCount, tint);
}
}
}
/// <summary>Draw text (using default font)</summary>
public static void DrawText(string text, int posX, int posY, int fontSize, Color color)
{
using var str1 = text.ToUTF8Buffer();
DrawText(str1.AsPointer(), posX, posY, fontSize, color);
}
/// <summary>Draw text using font and additional parameters</summary>
public static void DrawTextEx(Font font, string text, Vector2 position, float fontSize, float spacing, Color tint)
{
using var str1 = text.ToUTF8Buffer();
DrawTextEx(font, str1.AsPointer(), position, fontSize, spacing, tint);
}
/// <summary>Draw text using Font and pro parameters (rotation)</summary>
public static void DrawTextPro(Font font, string text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint)
{
using var str1 = text.ToUTF8Buffer();
DrawTextPro(font, str1.AsPointer(), position, origin, rotation, fontSize, spacing, tint);
}
/// <summary>Measure string width for default font</summary>
public static int MeasureText(string text, int fontSize)
{
using var str1 = text.ToUTF8Buffer();
return MeasureText(str1.AsPointer(), fontSize);
}
/// <summary>Measure string size for Font</summary>
public static Vector2 MeasureTextEx(Font font, string text, float fontSize, float spacing)
{
using var str1 = text.ToUTF8Buffer();
return MeasureTextEx(font, str1.AsPointer(), fontSize, spacing);
}
/// <summary>Append text at specific position and move cursor!</summary>
public static void TextAppend(string text, string append, int position)
{
using var str1 = text.ToUTF8Buffer();
using var str2 = append.ToUTF8Buffer();
TextAppend(str1.AsPointer(), str2.AsPointer(), &position);
}
/// <summary>Get Pascal case notation version of provided string</summary>
public static string TextToPascal(string text)
{
using var str1 = text.ToUTF8Buffer();
return Utf8StringUtils.GetUTF8String(TextToPascal(str1.AsPointer()));
}
/// <summary>Get integer value from text (negative values not supported)</summary>
public static int TextToInteger(string text)
{
using var str1 = text.ToUTF8Buffer();
return TextToInteger(str1.AsPointer());
}
/// <summary>Get all codepoints in a string, codepoints count returned by parameters</summary>
public static int[] LoadCodepoints(string text, ref int count)
{
using var str1 = text.ToUTF8Buffer();
fixed (int* c = &count)
{
var pointsPtr = LoadCodepoints(str1.AsPointer(), c);
var codepoints = new ReadOnlySpan<int>(pointsPtr, count).ToArray();
UnloadCodepoints(pointsPtr);
return codepoints;
}
}
/// <summary>Get total number of characters (codepoints) in a UTF8 encoded string</summary>
public static int GetCodepointCount(string text)
{
using var str1 = text.ToUTF8Buffer();
return GetCodepointCount(str1.AsPointer());
}
/// <summary>Returns next codepoint in a UTF8 encoded string; 0x3f('?') is returned on failure</summary>
/// <returns>single codepoint / "char"</returns>
public static int GetCodepoint(string text, ref int bytesProcessed)
{
using var str1 = text.ToUTF8Buffer();
fixed (int* p = &bytesProcessed)
{
return GetCodepoint(str1.AsPointer(), p);
}
}
/// <summary>Encode codepoint into utf8 text (char array length returned as parameter)</summary>
public static string CodepointToUTF8(int codepoint, ref int byteSize)
{
fixed (int* l1 = &byteSize)
{
var ptr = CodepointToUTF8(codepoint, l1);
return Utf8StringUtils.GetUTF8String(ptr);
}
}
/// <summary>Encode codepoint into utf8 text (char array length returned as parameter)</summary>
public static string TextCodepointsToUTF8(int[] codepoints, int length)
{
fixed (int* c1 = codepoints)
{
var ptr = TextCodepointsToUTF8(c1, length);
var text = Utf8StringUtils.GetUTF8String(ptr);
MemFree(ptr);
return text;
}
}
/// <summary>Draw a model (with texture if set)</summary>
public static Model LoadModel(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadModel(str1.AsPointer());
}
/// <summary>Export mesh data to file, returns true on success</summary>
public static CBool ExportMesh(Mesh mesh, string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
return ExportMesh(mesh, str1.AsPointer());
}
/// <summary>Draw a triangle strip defined by points</summary>
public static void DrawTriangleStrip3D(Vector3[] points, int pointsCount, Color color)
{
fixed (Vector3* p = points)
{
DrawTriangleStrip3D(p, pointsCount, color);
}
}
/// <summary>Draw multiple mesh instances with material and different transforms</summary>
public static void DrawMeshInstanced(Mesh mesh, Material material, Matrix4x4[] transforms, int instances)
{
fixed (Matrix4x4* p = transforms)
{
DrawMeshInstanced(mesh, material, p, instances);
}
}
/// <summary>Load wave data from file</summary>
public static Wave LoadWave(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadWave(str1.AsPointer());
}
/// <summary>Load sound from file</summary>
public static Sound LoadSound(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadSound(str1.AsPointer());
}
/// <summary>Export wave data to file</summary>
public static void ExportWave(Wave wave, string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
ExportWave(wave, str1.AsPointer());
}
/// <summary>Export wave sample data to code (.h)</summary>
public static void ExportWaveAsCode(Wave wave, string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
ExportWaveAsCode(wave, str1.AsPointer());
}
/// <summary>Load music stream from file</summary>
public static Music LoadMusicStream(string fileName)
{
using var str1 = fileName.ToUTF8Buffer();
return LoadMusicStream(str1.AsPointer());
}
public static string SubText(this string input, int position, int length)
{
return input.Substring(position, Math.Min(length, input.Length));
}
public static Material GetMaterial(ref Model model, int materialIndex)
{
return model.materials[materialIndex];
}
public static Texture2D GetMaterialTexture(ref Model model, int materialIndex, MaterialMapIndex mapIndex)
{
return model.materials[materialIndex].maps[(int)mapIndex].texture;
}
public static void SetMaterialTexture(ref Model model, int materialIndex, MaterialMapIndex mapIndex, ref Texture2D texture)
{
SetMaterialTexture(&model.materials[materialIndex], mapIndex, texture);
}
public static void SetMaterialShader(ref Model model, int materialIndex, ref Shader shader)
{
model.materials[materialIndex].shader = shader;
}
}
}

View File

@ -0,0 +1,29 @@
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// Rectangle type
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct Rectangle
{
public float x;
public float y;
public float width;
public float height;
public Rectangle(float x, float y, float width, float height)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public override string ToString()
{
return $"{{X:{x} Y:{y} Width:{width} Height:{height}}}";
}
}
}

View File

@ -0,0 +1,271 @@
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// RenderBatch type
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct RenderBatch
{
/// <summary>
/// Number of vertex buffers (multi-buffering support)
/// </summary>
int buffersCount;
/// <summary>
/// Current buffer tracking in case of multi-buffering
/// </summary>
int currentBuffer;
/// <summary>
/// Dynamic buffer(s) for vertex data
/// </summary>
VertexBuffer* vertexBuffer;
/// <summary>
/// Draw calls array, depends on textureId
/// </summary>
DrawCall* draws;
/// <summary>
/// Draw calls counter
/// </summary>
int drawsCounter;
/// <summary>
/// Current depth value for next draw
/// </summary>
float currentDepth;
}
/// <summary>
/// Dynamic vertex buffers (position + texcoords + colors + indices arrays)
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct VertexBuffer
{
/// <summary>
/// Number of elements in the buffer (QUADS)
/// </summary>
public int elementCount;
/// <summary>
/// Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
/// </summary>
public float* vertices;
/// <summary>
/// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
/// </summary>
public float* texcoords;
/// <summary>
/// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
/// </summary>
public byte* colors;
/// <summary>
/// Vertex indices (in case vertex data comes indexed) (6 indices per quad)<br/>
/// unsigned int* for GRAPHICS_API_OPENGL_11 or GRAPHICS_API_OPENGL_33<br/>
/// unsigned short* for GRAPHICS_API_OPENGL_ES2
/// </summary>
public void* indices;
/// <summary>
/// OpenGL Vertex Array Object id
/// </summary>
public uint vaoId;
/// <summary>
/// OpenGL Vertex Buffer Objects id (4 types of vertex data)
/// </summary>
public fixed uint vboId[4];
}
/// <summary>
/// Dynamic vertex buffers (position + texcoords + colors + indices arrays)
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct DrawCall
{
/// <summary>
/// Drawing mode: LINES, TRIANGLES, QUADS
/// </summary>
int mode;
/// <summary>
/// Number of vertices for the draw call
/// </summary>
int vertexCount;
/// <summary>
/// Number of vertices required for index alignment (LINES, TRIANGLES)
/// </summary>
int vertexAlignment;
/// <summary>
/// Texture id to be used on the draw -> Use to create new draw call if changes
/// </summary>
uint textureId;
}
public enum GlVersion
{
OPENGL_11 = 1,
OPENGL_21,
OPENGL_33,
OPENGL_43,
OPENGL_ES_20
}
public enum FramebufferAttachType
{
RL_ATTACHMENT_COLOR_CHANNEL0 = 0,
RL_ATTACHMENT_COLOR_CHANNEL1,
RL_ATTACHMENT_COLOR_CHANNEL2,
RL_ATTACHMENT_COLOR_CHANNEL3,
RL_ATTACHMENT_COLOR_CHANNEL4,
RL_ATTACHMENT_COLOR_CHANNEL5,
RL_ATTACHMENT_COLOR_CHANNEL6,
RL_ATTACHMENT_COLOR_CHANNEL7,
RL_ATTACHMENT_DEPTH = 100,
RL_ATTACHMENT_STENCIL = 200,
}
public enum FramebufferAttachTextureType
{
RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0,
RL_ATTACHMENT_CUBEMAP_NEGATIVE_X,
RL_ATTACHMENT_CUBEMAP_POSITIVE_Y,
RL_ATTACHMENT_CUBEMAP_NEGATIVE_Y,
RL_ATTACHMENT_CUBEMAP_POSITIVE_Z,
RL_ATTACHMENT_CUBEMAP_NEGATIVE_Z,
RL_ATTACHMENT_TEXTURE2D = 100,
RL_ATTACHMENT_RENDERBUFFER = 200,
}
/// <summary>
/// Matrix Modes (equivalent to OpenGL)
/// </summary>
public enum MatrixMode
{
/// <summary>
/// GL_MODELVIEW
/// </summary>
MODELVIEW = 0x1700,
/// <summary>
/// GL_PROJECTION
/// </summary>
PROJECTION = 0x1701,
/// <summary>
/// GL_TEXTURE
/// </summary>
TEXTURE = 0x1702
}
/// <summary>
/// Primitive assembly draw modes
/// </summary>
public enum DrawMode
{
/// <summary>
/// GL_LINES
/// </summary>
LINES = 0x0001,
/// <summary>
/// GL_TRIANGLES
/// </summary>
TRIANGLES = 0x0004,
/// <summary>
/// GL_QUADS
/// </summary>
QUADS = 0x0007
}
/// <summary>
/// Texture parameters (equivalent to OpenGL defines)
/// </summary>
public enum TextureFilters
{
/// <summary>
/// RL_TEXTURE_FILTER_NEAREST
/// <br/>
/// GL_NEAREST
/// </summary>
NEAREST = 0x2600,
/// <summary>
/// RL_TEXTURE_FILTER_LINEAR
/// <br/>
/// GL_LINEAR
/// </summary>
LINEAR = 0x2601,
/// <summary>
/// RL_TEXTURE_FILTER_MIP_NEAREST
/// <br/>
/// GL_NEAREST_MIPMAP_NEAREST
/// </summary>
MIP_NEAREST = 0x2700,
/// <summary>
/// RL_TEXTURE_FILTER_NEAREST_MIP_LINEAR
/// <br/>
/// GL_NEAREST_MIPMAP_LINEAR
/// </summary>
NEAREST_MIP_LINEAR = 0x2702,
/// <summary>
/// RL_TEXTURE_FILTER_LINEAR_MIP_NEAREST
/// <br/>
/// GL_LINEAR_MIPMAP_NEAREST
/// </summary>
LINEAR_MIP_NEAREST = 0x2701,
/// <summary>
/// RL_TEXTURE_FILTER_MIP_LINEAR
/// <br/>
/// GL_LINEAR_MIPMAP_LINEAR
/// </summary>
MIP_LINEAR = 0x2703,
/// <summary>
/// RL_TEXTURE_FILTER_ANISOTROPIC
/// <br/>
/// Anisotropic filter (custom identifier)
/// </summary>
ANISOTROPIC = 0x3000
}
/// <summary>
/// GL Shader type
/// </summary>
public enum ShaderType
{
/// <summary>
/// RL_FRAGMENT_SHADER
/// <br/>
/// GL_FRAGMENT_SHADER
/// </summary>
FRAGMENT = 0x8B30,
/// <summary>
/// RL_VERTEX_SHADER
/// <br/>
/// GL_VERTEX_SHADER
/// </summary>
VERTEX = 0x8B31,
/// <summary>
/// RL_COMPUTE_SHADER
/// <br/>
/// GL_COMPUTE_SHADER
/// </summary>
COMPUTE = 0x91b9
}
}

View File

@ -0,0 +1,26 @@
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// RenderTexture2D type, for texture rendering
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct RenderTexture2D
{
/// <summary>
/// OpenGL Framebuffer Object (FBO) id
/// </summary>
public uint id;
/// <summary>
/// Color buffer attachment texture
/// </summary>
public Texture2D texture;
/// <summary>
/// Depth buffer attachment texture
/// </summary>
public Texture2D depth;
}
}

85
Raylib-cs/types/Shader.cs Normal file
View File

@ -0,0 +1,85 @@
using System;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// Shader location index
/// </summary>
public enum ShaderLocationIndex
{
SHADER_LOC_VERTEX_POSITION = 0,
SHADER_LOC_VERTEX_TEXCOORD01,
SHADER_LOC_VERTEX_TEXCOORD02,
SHADER_LOC_VERTEX_NORMAL,
SHADER_LOC_VERTEX_TANGENT,
SHADER_LOC_VERTEX_COLOR,
SHADER_LOC_MATRIX_MVP,
SHADER_LOC_MATRIX_VIEW,
SHADER_LOC_MATRIX_PROJECTION,
SHADER_LOC_MATRIX_MODEL,
SHADER_LOC_MATRIX_NORMAL,
SHADER_LOC_VECTOR_VIEW,
SHADER_LOC_COLOR_DIFFUSE,
SHADER_LOC_COLOR_SPECULAR,
SHADER_LOC_COLOR_AMBIENT,
SHADER_LOC_MAP_ALBEDO,
SHADER_LOC_MAP_METALNESS,
SHADER_LOC_MAP_NORMAL,
SHADER_LOC_MAP_ROUGHNESS,
SHADER_LOC_MAP_OCCLUSION,
SHADER_LOC_MAP_EMISSION,
SHADER_LOC_MAP_HEIGHT,
SHADER_LOC_MAP_CUBEMAP,
SHADER_LOC_MAP_IRRADIANCE,
SHADER_LOC_MAP_PREFILTER,
SHADER_LOC_MAP_BRDF,
SHADER_LOC_MAP_DIFFUSE = SHADER_LOC_MAP_ALBEDO,
SHADER_LOC_MAP_SPECULAR = SHADER_LOC_MAP_METALNESS,
}
/// <summary>
/// Shader attribute data types
/// </summary>
public enum ShaderAttributeDataType
{
SHADER_ATTRIB_FLOAT = 0,
SHADER_ATTRIB_VEC2,
SHADER_ATTRIB_VEC3,
SHADER_ATTRIB_VEC4
}
/// <summary>
/// Shader uniform data type
/// </summary>
public enum ShaderUniformDataType
{
SHADER_UNIFORM_FLOAT = 0,
SHADER_UNIFORM_VEC2,
SHADER_UNIFORM_VEC3,
SHADER_UNIFORM_VEC4,
SHADER_UNIFORM_INT,
SHADER_UNIFORM_IVEC2,
SHADER_UNIFORM_IVEC3,
SHADER_UNIFORM_IVEC4,
SHADER_UNIFORM_SAMPLER2D
}
/// <summary>
/// Shader type (generic)
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Shader
{
/// <summary>
/// Shader program id
/// </summary>
public uint id;
/// <summary>
/// Shader locations array (MAX_SHADER_LOCATIONS, int *)
/// </summary>
public int* locs;
}
}

View File

@ -0,0 +1,137 @@
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// Texture parameters: filter mode<br/>
/// NOTE 1: Filtering considers mipmaps if available in the texture<br/>
/// NOTE 2: Filter is accordingly set for minification and magnification
/// </summary>
public enum TextureFilter
{
/// <summary>
/// No filter, just pixel aproximation
/// </summary>
TEXTURE_FILTER_POINT = 0,
/// <summary>
/// Linear filtering
/// </summary>
TEXTURE_FILTER_BILINEAR,
/// <summary>
/// Trilinear filtering (linear with mipmaps)
/// </summary>
TEXTURE_FILTER_TRILINEAR,
/// <summary>
/// Anisotropic filtering 4x
/// </summary>
TEXTURE_FILTER_ANISOTROPIC_4X,
/// <summary>
/// Anisotropic filtering 8x
/// </summary>
TEXTURE_FILTER_ANISOTROPIC_8X,
/// <summary>
/// Anisotropic filtering 16x
/// </summary>
TEXTURE_FILTER_ANISOTROPIC_16X,
}
/// <summary>
/// Texture parameters: wrap mode
/// </summary>
public enum TextureWrap
{
/// <summary>
/// Repeats texture in tiled mode
/// </summary>
TEXTURE_WRAP_REPEAT = 0,
/// <summary>
/// Clamps texture to edge pixel in tiled mode
/// </summary>
TEXTURE_WRAP_CLAMP,
/// <summary>
/// Mirrors and repeats the texture in tiled mode
/// </summary>
TEXTURE_WRAP_MIRROR_REPEAT,
/// <summary>
/// Mirrors and clamps to border the texture in tiled mode
/// </summary>
TEXTURE_WRAP_MIRROR_CLAMP
}
/// <summary>
/// Cubemap layouts
/// </summary>
public enum CubemapLayout
{
/// <summary>
/// Automatically detect layout type
/// </summary>
CUBEMAP_LAYOUT_AUTO_DETECT = 0,
/// <summary>
/// Layout is defined by a vertical line with faces
/// </summary>
CUBEMAP_LAYOUT_LINE_VERTICAL,
/// <summary>
/// Layout is defined by an horizontal line with faces
/// </summary>
CUBEMAP_LAYOUT_LINE_HORIZONTAL,
/// <summary>
/// Layout is defined by a 3x4 cross with cubemap faces
/// </summary>
CUBEMAP_LAYOUT_CROSS_THREE_BY_FOUR,
/// <summary>
/// Layout is defined by a 4x3 cross with cubemap faces
/// </summary>
CUBEMAP_LAYOUT_CROSS_FOUR_BY_THREE,
/// <summary>
/// Layout is defined by a panorama image (equirectangular map)
/// </summary>
CUBEMAP_LAYOUT_PANORAMA
}
/// <summary>
/// Texture2D type<br/>
/// NOTE: Data stored in GPU memory
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct Texture2D
{
/// <summary>
/// OpenGL texture id
/// </summary>
public uint id;
/// <summary>
/// Texture base width
/// </summary>
public int width;
/// <summary>
/// Texture base height
/// </summary>
public int height;
/// <summary>
/// Mipmap levels, 1 by default
/// </summary>
public int mipmaps;
/// <summary>
/// Data format (PixelFormat type)
/// </summary>
public PixelFormat format;
}
}

View File

@ -0,0 +1,27 @@
using System.Numerics;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// Transform, vectex transformation data
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public partial struct Transform
{
/// <summary>
/// Translation
/// </summary>
public Vector3 translation;
/// <summary>
/// Rotation
/// </summary>
public Vector4 rotation;
/// <summary>
/// Scale
/// </summary>
public Vector3 scale;
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
[StructLayout(LayoutKind.Sequential)]
public readonly struct CBool
{
private readonly byte value;
private CBool(bool value)
{
this.value = Convert.ToByte(value);
}
public static implicit operator CBool(bool value)
{
return new CBool(value);
}
public static implicit operator bool(CBool x)
{
return Convert.ToBoolean(x.value);
}
public override string ToString()
{
return Convert.ToBoolean(value).ToString();
}
}
}

View File

@ -0,0 +1,64 @@
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace Raylib_cs
{
/// <summary>
/// Converts text to a UTF8 buffer for passing to native code.<br/>
/// Uses ArrayPool to reduce memory allocation.
/// </summary>
public ref struct UTF8Buffer
{
private IntPtr data;
public UTF8Buffer(string text)
{
data = Marshal.StringToCoTaskMemUTF8(text);
}
public unsafe sbyte* AsPointer()
{
return (sbyte*)data.ToPointer();
}
public void Dispose()
{
Marshal.FreeCoTaskMem(data);
}
}
public static class Utf8StringUtils
{
public static UTF8Buffer ToUTF8Buffer(this string text)
{
return new UTF8Buffer(text);
}
public static byte[] ToUtf8String(this string text)
{
if (text == null)
{
return null;
}
var length = Encoding.UTF8.GetByteCount(text);
var byteArray = new byte[length + 1];
var wrote = Encoding.UTF8.GetBytes(text, 0, text.Length, byteArray, 0);
byteArray[wrote] = 0;
return byteArray;
}
public static unsafe string GetUTF8String(sbyte* bytes)
{
return Marshal.PtrToStringUTF8((IntPtr)bytes);
}
public static byte[] GetUTF8Bytes(this string text)
{
return Encoding.UTF8.GetBytes(text);
}
}
}