├── .github
├── FUNDING.yml
├── ISSUE_TEMPLATE
│ ├── -feature-.md
│ └── -bug-.md
└── workflows
│ └── build.yml
├── src
├── Raylib-CSharp
│ ├── icon.png
│ ├── Rendering
│ │ ├── Gl
│ │ │ ├── CullMode.cs
│ │ │ ├── DrawMode.cs
│ │ │ ├── MatrixMode.cs
│ │ │ ├── Contexts
│ │ │ │ ├── IGlContext.cs
│ │ │ │ ├── MacOsGlContext.cs
│ │ │ │ ├── NativeGlContext.cs
│ │ │ │ ├── LinuxGlContext.cs
│ │ │ │ └── WinGlContext.cs
│ │ │ ├── GlVersion.cs
│ │ │ ├── DrawCall.cs
│ │ │ ├── FrameBuffer
│ │ │ │ ├── FramebufferAttachTextureType.cs
│ │ │ │ └── FramebufferAttachType.cs
│ │ │ ├── RenderBatch.cs
│ │ │ └── VertexBuffer.cs
│ │ ├── NPatchLayout.cs
│ │ ├── NPatchInfo.cs
│ │ └── BlendMode.cs
│ ├── Camera
│ │ ├── Cam3D
│ │ │ ├── CameraProjection.cs
│ │ │ ├── CameraMode.cs
│ │ │ └── Camera3D.cs
│ │ └── Cam2D
│ │ │ └── Camera2D.cs
│ ├── Fonts
│ │ ├── FontType.cs
│ │ ├── GlyphInfo.cs
│ │ ├── Font.cs
│ │ └── TextManager.cs
│ ├── Transformations
│ │ ├── Transform.cs
│ │ └── Rectangle.cs
│ ├── Shaders
│ │ ├── ShaderAttributeDataType.cs
│ │ ├── ShaderUniformDataType.cs
│ │ ├── Shader.cs
│ │ └── ShaderLocationIndex.cs
│ ├── Materials
│ │ ├── MaterialMap.cs
│ │ ├── MaterialMapIndex.cs
│ │ └── Material.cs
│ ├── Textures
│ │ ├── TextureWrap.cs
│ │ ├── CubemapLayout.cs
│ │ ├── TextureFilter.cs
│ │ ├── RenderTexture2D.cs
│ │ └── Texture2D.cs
│ ├── Collision
│ │ ├── RayCollision.cs
│ │ ├── BoundingBox.cs
│ │ ├── Ray.cs
│ │ └── ShapeHelper.cs
│ ├── IO
│ │ ├── FilePathList.cs
│ │ └── FileManager.cs
│ ├── Interact
│ │ ├── GamepadAxis.cs
│ │ ├── MouseButton.cs
│ │ ├── Gesture.cs
│ │ ├── MouseCursor.cs
│ │ └── GamepadButton.cs
│ ├── Geometry
│ │ ├── BoneInfo.cs
│ │ ├── ModelAnimation.cs
│ │ └── Model.cs
│ ├── Time.cs
│ ├── Audio
│ │ ├── AudioDevice.cs
│ │ ├── Sound.cs
│ │ ├── Wave.cs
│ │ ├── Music.cs
│ │ └── AudioStream.cs
│ ├── Logging
│ │ ├── TraceLogLevel.cs
│ │ └── Logger.cs
│ ├── Unsafe
│ │ ├── Spans
│ │ │ ├── Data
│ │ │ │ ├── SpanData.cs
│ │ │ │ └── ReadOnlySpanData.cs
│ │ │ └── Custom
│ │ │ │ ├── StringArraySpan.cs
│ │ │ │ └── FixedArraySpan.cs
│ │ ├── Marshallers
│ │ │ └── NonFreeUtf8StringMarshaller.cs
│ │ └── FixedString.cs
│ ├── Automations
│ │ ├── AutomationEventList.cs
│ │ ├── AutomationEvent.cs
│ │ └── AutomationEventType.cs
│ ├── Raylib-CSharp.csproj
│ ├── Vr
│ │ ├── VrStereoConfig.cs
│ │ └── VrDeviceInfo.cs
│ ├── Windowing
│ │ └── ConfigFlags.cs
│ ├── Raylib.cs
│ ├── Images
│ │ └── PixelFormat.cs
│ └── Colors
│ │ └── Color.cs
├── Raylib-CSharp.Test
│ ├── content
│ │ ├── fontoe.ttf
│ │ ├── model.glb
│ │ └── texture.png
│ ├── Raylib-CSharp.Test.csproj
│ ├── NativeBindingsContext.cs
│ ├── CMake.props
│ └── Program.cs
└── Raylib-CSharp.Samples
│ ├── ISample.cs
│ ├── Core
│ ├── BasicWindow.cs
│ ├── CustomLogger.cs
│ ├── SpinningAroundADiamond.cs
│ └── Pong.cs
│ ├── Raylib-CSharp.Samples.csproj
│ ├── SamplesMenu.cs
│ ├── Program.cs
│ └── CMake.props
├── global.json
├── CONTRIBUTING.md
├── LICENSE
├── Raylib-CSharp.sln
├── .gitignore
├── README.md
└── CODE_OF_CONDUCT.md
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: [MrScautHD]
2 |
--------------------------------------------------------------------------------
/src/Raylib-CSharp/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MrScautHD/Raylib-CSharp/HEAD/src/Raylib-CSharp/icon.png
--------------------------------------------------------------------------------
/global.json:
--------------------------------------------------------------------------------
1 | {
2 | "sdk": {
3 | "version": "8.0.0",
4 | "rollForward": "latestMajor",
5 | "allowPrerelease": true
6 | }
7 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp.Test/content/fontoe.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MrScautHD/Raylib-CSharp/HEAD/src/Raylib-CSharp.Test/content/fontoe.ttf
--------------------------------------------------------------------------------
/src/Raylib-CSharp.Test/content/model.glb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MrScautHD/Raylib-CSharp/HEAD/src/Raylib-CSharp.Test/content/model.glb
--------------------------------------------------------------------------------
/src/Raylib-CSharp.Test/content/texture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MrScautHD/Raylib-CSharp/HEAD/src/Raylib-CSharp.Test/content/texture.png
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Rendering/Gl/CullMode.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Rendering.Gl;
2 |
3 | public enum CullMode {
4 | CullFaceFront = 0,
5 | CullFaceBack
6 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp.Samples/ISample.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Samples;
2 |
3 | public interface ISample : IDisposable {
4 |
5 | ///
6 | /// Executes the sample code.
7 | ///
8 | void Run();
9 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Camera/Cam3D/CameraProjection.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Camera.Cam3D;
2 |
3 | public enum CameraProjection {
4 |
5 | ///
6 | /// Perspective projection.
7 | ///
8 | Perspective = 0,
9 |
10 | ///
11 | /// Orthographic projection.
12 | ///
13 | Orthographic
14 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Rendering/Gl/DrawMode.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Rendering.Gl;
2 |
3 | public enum DrawMode {
4 |
5 | ///
6 | /// GL_LINES.
7 | ///
8 | Lines = 0x0001,
9 |
10 | ///
11 | /// GL_TRIANGLES.
12 | ///
13 | Triangles = 0x0004,
14 |
15 | ///
16 | /// GL_QUADS.
17 | ///
18 | Quads = 0x0007
19 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Rendering/Gl/MatrixMode.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Rendering.Gl;
2 |
3 | public enum MatrixMode {
4 |
5 | ///
6 | /// GL_MODELVIEW.
7 | ///
8 | ModelView = 0x1700,
9 |
10 | ///
11 | /// GL_PROJECTION.
12 | ///
13 | Projection = 0x1701,
14 |
15 | ///
16 | /// GL_TEXTURE.
17 | ///
18 | Texture = 0x1702
19 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Fonts/FontType.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Fonts;
2 |
3 | public enum FontType {
4 |
5 | ///
6 | /// Default font generation, anti-aliased.
7 | ///
8 | Default = 0,
9 |
10 | ///
11 | /// Bitmap font generation, no anti-aliasing.
12 | ///
13 | Bitmap,
14 |
15 | ///
16 | /// SDF font generation, requires external shader.
17 | ///
18 | Sdf
19 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Rendering/NPatchLayout.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Rendering;
2 |
3 | public enum NPatchLayout {
4 |
5 | ///
6 | /// Npatch defined by 3x3 tiles.
7 | ///
8 | NinePatch = 0,
9 |
10 | ///
11 | /// Npatch defined by 1x3 tiles.
12 | ///
13 | ThreePatchVertical,
14 |
15 | ///
16 | /// Npatch defined by 3x1 tiles.
17 | ///
18 | ThreePatchHorizontal
19 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Transformations/Transform.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace Raylib_CSharp.Transformations;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct Transform {
8 |
9 | ///
10 | /// Translation.
11 | ///
12 | public Vector3 Translation;
13 |
14 | ///
15 | /// Rotation.
16 | ///
17 | public Quaternion Rotation;
18 |
19 | ///
20 | /// Scale.
21 | ///
22 | public Vector3 Scale;
23 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Shaders/ShaderAttributeDataType.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Shaders;
2 |
3 | public enum ShaderAttributeDataType {
4 |
5 | ///
6 | /// Shader attribute type: float
7 | ///
8 | Float = 0,
9 |
10 | ///
11 | /// Shader attribute type: vec2 (2 float)
12 | ///
13 | Vec2,
14 |
15 | ///
16 | /// Shader attribute type: vec3 (3 float)
17 | ///
18 | Vec3,
19 |
20 | ///
21 | /// Shader attribute type: vec4 (4 float)
22 | ///
23 | Vec4
24 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Rendering/Gl/Contexts/IGlContext.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Rendering.Gl.Contexts;
2 |
3 | public interface IGlContext {
4 |
5 | ///
6 | /// Retrieves the address of an exported function or variable from the specified dynamic-link library (DLL).
7 | ///
8 | /// The name of the exported function or variable to retrieve the address of.
9 | /// A handle to the exported function or variable if successful; otherwise, .
10 | nint GetProcAddress(string procName);
11 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Materials/MaterialMap.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Raylib_CSharp.Colors;
3 | using Raylib_CSharp.Textures;
4 |
5 | namespace Raylib_CSharp.Materials;
6 |
7 | [StructLayout(LayoutKind.Sequential)]
8 | public struct MaterialMap {
9 |
10 | ///
11 | /// Material map texture.
12 | ///
13 | public Texture2D Texture;
14 |
15 | ///
16 | /// Material map color.
17 | ///
18 | public Color Color;
19 |
20 | ///
21 | /// Material map value.
22 | ///
23 | public float Value;
24 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Textures/TextureWrap.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Textures;
2 |
3 | public enum TextureWrap {
4 |
5 | ///
6 | /// Repeats texture in tiled mode.
7 | ///
8 | Repeat = 0,
9 |
10 | ///
11 | /// Clamps texture to edge pixel in tiled mode.
12 | ///
13 | Clamp,
14 |
15 | ///
16 | /// Mirrors and repeats the texture in tiled mode.
17 | ///
18 | MirrorRepeat,
19 |
20 | ///
21 | /// Mirrors and clamps to border the texture in tiled mode.
22 | ///
23 | MirrorClamp
24 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp.Samples/Core/BasicWindow.cs:
--------------------------------------------------------------------------------
1 | using Raylib_CSharp.Colors;
2 | using Raylib_CSharp.Rendering;
3 | using Raylib_CSharp.Windowing;
4 |
5 | namespace Raylib_CSharp.Samples.Core;
6 |
7 | public class BasicWindow : ISample {
8 |
9 | public void Run() {
10 | Window.Init(1280, 720, "Basic Window");
11 |
12 | while (!Window.ShouldClose()) {
13 | Graphics.BeginDrawing();
14 | Graphics.ClearBackground(Color.SkyBlue);
15 |
16 | Graphics.DrawText("Basic Window!", 10, 10, 20, Color.White);
17 |
18 | Graphics.EndDrawing();
19 | }
20 | }
21 |
22 | public void Dispose() {
23 | Window.Close();
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Camera/Cam3D/CameraMode.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Camera.Cam3D;
2 |
3 | public enum CameraMode {
4 |
5 | ///
6 | /// Camera custom, controlled by user (UpdateCamera() does nothing).
7 | ///
8 | Custom = 0,
9 |
10 | ///
11 | /// Camera free mode.
12 | ///
13 | Free,
14 |
15 | ///
16 | /// Camera orbital, around target, zoom supported.
17 | ///
18 | Orbital,
19 |
20 | ///
21 | /// Camera first person.
22 | ///
23 | FirstPerson,
24 |
25 | ///
26 | /// Camera third person.
27 | ///
28 | ThirdPerson
29 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Collision/RayCollision.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace Raylib_CSharp.Collision;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct RayCollision {
8 |
9 | ///
10 | /// Did the ray hit something?
11 | ///
12 | public bool Hit;
13 |
14 | ///
15 | /// Distance to the nearest hit.
16 | ///
17 | public float Distance;
18 |
19 | ///
20 | /// Point of the nearest hit.
21 | ///
22 | public Vector3 Point;
23 |
24 | ///
25 | /// Surface normal of hit.
26 | ///
27 | public Vector3 Normal;
28 | }
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/-feature-.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: "[Feature]"
3 | about: Suggest an idea for this project
4 | title: "[Feature]"
5 | labels: enhancement
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/src/Raylib-CSharp/IO/FilePathList.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Raylib_CSharp.Unsafe.Spans.Custom;
3 |
4 | namespace Raylib_CSharp.IO;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct FilePathList {
8 |
9 | ///
10 | /// FilePaths max entries.
11 | ///
12 | public uint Capacity;
13 |
14 | ///
15 | /// FilePaths entries count.
16 | ///
17 | public uint Count;
18 |
19 | ///
20 | /// FilePaths entries.
21 | ///
22 | public unsafe sbyte** PathsPtr;
23 |
24 | ///
25 | public unsafe StringArraySpan Paths => new(this.PathsPtr, (int) this.Count);
26 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp.Samples/Raylib-CSharp.Samples.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | Raylib_CSharp.Samples
7 | enable
8 | enable
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Rendering/Gl/GlVersion.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Rendering.Gl;
2 |
3 | public enum GlVersion {
4 |
5 | ///
6 | /// OpenGL 1.1.
7 | ///
8 | OpenGl11 = 1,
9 |
10 | ///
11 | /// OpenGL 2.1 (GLSL 120).
12 | ///
13 | OpenGl21,
14 |
15 | ///
16 | /// OpenGL 3.3 (GLSL 330).
17 | ///
18 | OpenGl33,
19 |
20 | ///
21 | /// OpenGL 4.3 (using GLSL 330).
22 | ///
23 | OpenGl43,
24 |
25 | ///
26 | /// OpenGL ES 2.0 (GLSL 100).
27 | ///
28 | OpenGlEs20,
29 |
30 | ///
31 | /// OpenGL ES 3.0 (GLSL 300 es).
32 | ///
33 | OpenGlEs30
34 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Textures/CubemapLayout.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Textures;
2 |
3 | public enum CubemapLayout {
4 |
5 | ///
6 | /// Automatically detect layout type.
7 | ///
8 | AutoDetect = 0,
9 |
10 | ///
11 | /// Layout is defined by a vertical line with faces.
12 | ///
13 | LineVertical,
14 |
15 | ///
16 | /// Layout is defined by a horizontal line with faces.
17 | ///
18 | LineHorizontal,
19 |
20 | ///
21 | /// Layout is defined by a 3x4 cross with cubemap faces.
22 | ///
23 | CrossThreeByFour,
24 |
25 | ///
26 | /// Layout is defined by a 4x3 cross with cubemap faces.
27 | ///
28 | CrossFourByThree
29 | }
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/-bug-.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: "[BUG]"
3 | about: Create a report to help us improve
4 | title: "[BUG]"
5 | labels: bug
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. Win11]
28 | - Version [e.g. 1.0.0]
29 |
30 | **Additional context**
31 | Add any other context about the problem here.
32 |
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Rendering/Gl/DrawCall.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 |
3 | namespace Raylib_CSharp.Rendering.Gl;
4 |
5 | [StructLayout(LayoutKind.Sequential)]
6 | public struct DrawCall {
7 |
8 | ///
9 | /// Drawing mode: LINES, TRIANGLES, QUADS.
10 | ///
11 | public DrawMode Mode;
12 |
13 | ///
14 | /// Number of vertex of the draw.
15 | ///
16 | public int VertexCount;
17 |
18 | ///
19 | /// Number of vertex required for index alignment (LINES, TRIANGLES).
20 | ///
21 | public int VertexAlignment;
22 |
23 | ///
24 | /// Texture id to be used on the draw -> Use to create new draw call if changes.
25 | ///
26 | public uint TextureId;
27 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Textures/TextureFilter.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Textures;
2 |
3 | public enum TextureFilter {
4 |
5 | ///
6 | /// No filter, just pixel approximation.
7 | ///
8 | Point = 0,
9 |
10 | ///
11 | /// Linear filtering.
12 | ///
13 | Bilinear,
14 |
15 | ///
16 | /// Trilinear filtering (linear with mipmaps).
17 | ///
18 | Trilinear,
19 |
20 | ///
21 | /// Anisotropic filtering 4x.
22 | ///
23 | Anisotropic4X,
24 |
25 | ///
26 | /// Anisotropic filtering 8x.
27 | ///
28 | Anisotropic8X,
29 |
30 | ///
31 | /// Anisotropic filtering 16x.
32 | ///
33 | Anisotropic16X
34 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Collision/BoundingBox.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace Raylib_CSharp.Collision;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct BoundingBox {
8 |
9 | ///
10 | /// Minimum vertex box-corner.
11 | ///
12 | public Vector3 Min;
13 |
14 | ///
15 | /// Maximum vertex box-corner.
16 | ///
17 | public Vector3 Max;
18 |
19 | ///
20 | /// Bounding box type.
21 | ///
22 | /// Minimum corner of the bounding box.
23 | /// Maximum corner of the bounding box.
24 | public BoundingBox(Vector3 min, Vector3 max) {
25 | this.Min = min;
26 | this.Max = max;
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Collision/Ray.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace Raylib_CSharp.Collision;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct Ray {
8 |
9 | ///
10 | /// Ray position (origin).
11 | ///
12 | public Vector3 Position;
13 |
14 | ///
15 | /// Ray direction.
16 | ///
17 | public Vector3 Direction;
18 |
19 | ///
20 | /// Ray, ray for RayCasting.
21 | ///
22 | /// Origin position of the ray.
23 | /// Direction of the ray.
24 | public Ray(Vector3 position, Vector3 direction) {
25 | this.Position = position;
26 | this.Direction = direction;
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Fonts/GlyphInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Raylib_CSharp.Images;
3 |
4 | namespace Raylib_CSharp.Fonts;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct GlyphInfo {
8 |
9 | ///
10 | /// Character value (Unicode).
11 | ///
12 | public int Value;
13 |
14 | ///
15 | /// Character offset X when drawing.
16 | ///
17 | public int OffsetX;
18 |
19 | ///
20 | /// Character offset Y when drawing.
21 | ///
22 | public int OffsetY;
23 |
24 | ///
25 | /// Character advance position X.
26 | ///
27 | public int AdvanceX;
28 |
29 | ///
30 | /// Character image data.
31 | ///
32 | public Image Image;
33 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Interact/GamepadAxis.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Interact;
2 |
3 | public enum GamepadAxis {
4 |
5 | ///
6 | /// Gamepad left stick X axis.
7 | ///
8 | LeftX = 0,
9 |
10 | ///
11 | /// Gamepad left stick Y axis.
12 | ///
13 | LeftY = 1,
14 |
15 | ///
16 | /// Gamepad right stick X axis.
17 | ///
18 | RightX = 2,
19 |
20 | ///
21 | /// Gamepad right stick Y axis.
22 | ///
23 | RightY = 3,
24 |
25 | ///
26 | /// Gamepad back trigger left, pressure level: [1..-1].
27 | ///
28 | LeftTrigger = 4,
29 |
30 | ///
31 | /// Gamepad back trigger right, pressure level: [1..-1].
32 | ///
33 | RightTrigger = 5
34 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Geometry/BoneInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Raylib_CSharp.Unsafe;
3 |
4 | namespace Raylib_CSharp.Geometry;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct BoneInfo {
8 |
9 | ///
10 | /// Bone name.
11 | ///
12 | public unsafe string Name {
13 | get {
14 | fixed (sbyte* namePtr = this.NamePtr) {
15 | return FixedString.GetValue(namePtr);
16 | }
17 | }
18 |
19 | set {
20 | fixed (sbyte* namePtr = this.NamePtr) {
21 | FixedString.SetValue(namePtr, 32, value);
22 | }
23 | }
24 | }
25 |
26 | public unsafe fixed sbyte NamePtr[32];
27 |
28 | ///
29 | /// Bone parent.
30 | ///
31 | public int Parent;
32 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Time.cs:
--------------------------------------------------------------------------------
1 | using Raylib_CSharp.Apis;
2 |
3 | namespace Raylib_CSharp;
4 |
5 | public static class Time {
6 |
7 | ///
8 | public static void SetTargetFPS(int fps) {
9 | RaylibApi.SetTargetFPS(fps);
10 | }
11 |
12 | ///
13 | public static float GetFrameTime() {
14 | return RaylibApi.GetFrameTime();
15 | }
16 |
17 | ///
18 | public static double GetTime() {
19 | return RaylibApi.GetTime();
20 | }
21 |
22 | ///
23 | public static int GetFPS() {
24 | return RaylibApi.GetFPS();
25 | }
26 |
27 | ///
28 | public static void WaitTime(double seconds) {
29 | RaylibApi.WaitTime(seconds);
30 | }
31 | }
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Get Involved with Raylib-CSharp
2 | Ready to dive into and make contributions? You're in the right place!
3 |
4 | ## Pull Requests
5 | Raylib-CSharp is an open-source project, and we eagerly welcome contributions from capable coders like you! Your assistance is invaluable to us.
6 |
7 | To ensure smooth integration, please adhere to the following guidelines when submitting your changes:
8 |
9 | 1. Commit with a clear, descriptive name that reflects the aspect you're addressing.
10 | 2. If you're fixing something not listed in the issues or not immediately apparent, provide explanatory comments detailing your changes.
11 | 3. Respect our code style; you can familiarize yourself with it by examining existing sources and following _.editorconfig_ suggestions.
12 |
13 | While pull requests not meeting these guidelines are still appreciated, they may require manual merging or additional changes by the author.
14 |
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Interact/MouseButton.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Interact;
2 |
3 | public enum MouseButton {
4 |
5 | ///
6 | /// Mouse button left.
7 | ///
8 | Left = 0,
9 |
10 | ///
11 | /// Mouse button right.
12 | ///
13 | Right = 1,
14 |
15 | ///
16 | /// Mouse button middle (pressed wheel).
17 | ///
18 | Middle = 2,
19 |
20 | ///
21 | /// Mouse button side (advanced mouse device).
22 | ///
23 | Side = 3,
24 |
25 | ///
26 | /// Mouse button extra (advanced mouse device).
27 | ///
28 | Extra = 4,
29 |
30 | ///
31 | /// Mouse button forward (advanced mouse device).
32 | ///
33 | Forward = 5,
34 |
35 | ///
36 | /// Mouse button back (advanced mouse device).
37 | ///
38 | Back = 6
39 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Rendering/NPatchInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Raylib_CSharp.Transformations;
3 |
4 | namespace Raylib_CSharp.Rendering;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct NPatchInfo {
8 |
9 | ///
10 | /// Texture source rectangle.
11 | ///
12 | public Rectangle Source;
13 |
14 | ///
15 | /// Left border offset.
16 | ///
17 | public int Left;
18 |
19 | ///
20 | /// Top border offset.
21 | ///
22 | public int Top;
23 |
24 | ///
25 | /// Right border offset.
26 | ///
27 | public int Right;
28 |
29 | ///
30 | /// Bottom border offset.
31 | ///
32 | public int Bottom;
33 |
34 | ///
35 | /// Layout of the n-patch: 3x3, 1x3 or 3x1.
36 | ///
37 | public NPatchLayout Layout;
38 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Audio/AudioDevice.cs:
--------------------------------------------------------------------------------
1 | using Raylib_CSharp.Apis;
2 |
3 | namespace Raylib_CSharp.Audio;
4 |
5 | public static class AudioDevice {
6 |
7 | ///
8 | public static void Init() {
9 | RaylibApi.InitAudioDevice();
10 | }
11 |
12 | ///
13 | public static void Close() {
14 | RaylibApi.CloseAudioDevice();
15 | }
16 |
17 | ///
18 | public static bool IsReady() {
19 | return RaylibApi.IsAudioDeviceReady();
20 | }
21 |
22 | ///
23 | public static void SetMasterVolume(float volume) {
24 | RaylibApi.SetMasterVolume(volume);
25 | }
26 |
27 | ///
28 | public static float GetMasterVolume() {
29 | return RaylibApi.GetMasterVolume();
30 | }
31 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp.Test/Raylib-CSharp.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | Raylib_CSharp.Test
7 | enable
8 | enable
9 | true
10 | false
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | PreserveNewest
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Logging/TraceLogLevel.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Logging;
2 |
3 | public enum TraceLogLevel {
4 |
5 | ///
6 | /// Display all logs.
7 | ///
8 | All = 0,
9 |
10 | ///
11 | /// Trace logging, intended for internal use only.
12 | ///
13 | Trace,
14 |
15 | ///
16 | /// Debug logging, used for internal debugging, it should be disabled on release builds.
17 | ///
18 | Debug,
19 |
20 | ///
21 | /// Info logging, used for program execution info.
22 | ///
23 | Info,
24 |
25 | ///
26 | /// Warning logging, used on recoverable failures.
27 | ///
28 | Warning,
29 |
30 | ///
31 | /// Error logging, used on unrecoverable failures.
32 | ///
33 | Error,
34 |
35 | ///
36 | /// Fatal logging, used to abort program: exit(EXIT_FAILURE).
37 | ///
38 | Fatal,
39 |
40 | ///
41 | /// Disable logging.
42 | ///
43 | None
44 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 MrScautHD
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Shaders/ShaderUniformDataType.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Shaders;
2 |
3 | public enum ShaderUniformDataType {
4 |
5 | ///
6 | /// Shader uniform type: float.
7 | ///
8 | Float = 0,
9 |
10 | ///
11 | /// Shader uniform type: vec2 (2 float).
12 | ///
13 | Vec2,
14 |
15 | ///
16 | /// Shader uniform type: vec3 (3 float).
17 | ///
18 | Vec3,
19 |
20 | ///
21 | /// Shader uniform type: vec4 (4 float).
22 | ///
23 | Vec4,
24 |
25 | ///
26 | /// Shader uniform type: int.
27 | ///
28 | Int,
29 |
30 | ///
31 | /// Shader uniform type: ivec2 (2 int).
32 | ///
33 | IVec2,
34 |
35 | ///
36 | /// Shader uniform type: ivec3 (3 int).
37 | ///
38 | IVec3,
39 |
40 | ///
41 | /// Shader uniform type: ivec4 (4 int).
42 | ///
43 | IVec4,
44 |
45 | ///
46 | /// Shader uniform type: sampler2d.
47 | ///
48 | Sampler2D
49 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Textures/RenderTexture2D.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Raylib_CSharp.Apis;
3 |
4 | namespace Raylib_CSharp.Textures;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct RenderTexture2D {
8 |
9 | ///
10 | /// OpenGL framebuffer object id.
11 | ///
12 | public uint Id;
13 |
14 | ///
15 | /// Color buffer attachment texture.
16 | ///
17 | public Texture2D Texture;
18 |
19 | ///
20 | /// Depth buffer attachment texture.
21 | ///
22 | public Texture2D Depth;
23 |
24 | ///
25 | public static RenderTexture2D Load(int width, int height) {
26 | return RaylibApi.LoadRenderTexture(width, height);
27 | }
28 |
29 | ///
30 | public bool IsValid() {
31 | return RaylibApi.IsRenderTextureValid(this);
32 | }
33 |
34 | ///
35 | public void Unload() {
36 | RaylibApi.UnloadRenderTexture(this);
37 | }
38 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Rendering/BlendMode.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Rendering;
2 |
3 | public enum BlendMode {
4 |
5 | ///
6 | /// Blend textures considering alpha (default).
7 | ///
8 | Alpha = 0,
9 |
10 | ///
11 | /// Blend textures adding colors.
12 | ///
13 | Additive,
14 |
15 | ///
16 | /// Blend textures multiplying colors.
17 | ///
18 | Multiplied,
19 |
20 | ///
21 | /// Blend textures adding colors (alternative).
22 | ///
23 | AddColors,
24 |
25 | ///
26 | /// Blend textures subtracting colors (alternative).
27 | ///
28 | SubtractColors,
29 |
30 | ///
31 | /// Blend premultiplied textures considering alpha.
32 | ///
33 | AlphaPremultiply,
34 |
35 | ///
36 | /// Blend textures using custom src/dst factors (use rlSetBlendFactors()).
37 | ///
38 | Custom,
39 |
40 | ///
41 | /// Blend textures using custom rgb/alpha separate src/dst factors (use rlSetBlendFactorsSeparate()).
42 | ///
43 | CustomSeparate
44 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Rendering/Gl/Contexts/MacOsGlContext.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace Raylib_CSharp.Rendering.Gl.Contexts;
5 |
6 | public partial class MacOsGlContext : IGlContext {
7 |
8 | private const string OpenGL = "/System/Library/Frameworks/OpenGL.framework/OpenGL";
9 |
10 | ///
11 | /// Retrieves the address of an OpenGL extension function.
12 | ///
13 | /// The name of the extension function.
14 | /// A pointer to the extension function if found; otherwise, .
15 | [LibraryImport(OpenGL, EntryPoint = "NSLookupAndBindSymbol", StringMarshalling = StringMarshalling.Utf8)]
16 | [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
17 | private static partial nint NSLookupAndBindSymbol(string procName);
18 |
19 | public nint GetProcAddress(string procName) {
20 | nint address = NSLookupAndBindSymbol($"_{procName}");
21 |
22 | if (address == nint.Zero) {
23 | throw new Exception("Failed to retrieve the Procedure Address.");
24 | }
25 |
26 | return address;
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Interact/Gesture.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Interact;
2 |
3 | [Flags]
4 | public enum Gesture : uint {
5 |
6 | ///
7 | /// No gesture.
8 | ///
9 | None = 0,
10 |
11 | ///
12 | /// Tap gesture.
13 | ///
14 | Tap = 1,
15 |
16 | ///
17 | /// Double tap gesture.
18 | ///
19 | DoubleTap = 2,
20 |
21 | ///
22 | /// Hold gesture.
23 | ///
24 | Hold = 4,
25 |
26 | ///
27 | /// Drag gesture.
28 | ///
29 | Drag = 8,
30 |
31 | ///
32 | /// Swipe right gesture.
33 | ///
34 | SwipeRight = 16,
35 |
36 | ///
37 | /// Swipe left gesture.
38 | ///
39 | SwipeLeft = 32,
40 |
41 | ///
42 | /// Swipe up gesture.
43 | ///
44 | SwipeUp = 64,
45 |
46 | ///
47 | /// Swipe down gesture.
48 | ///
49 | SwipeDown = 128,
50 |
51 | ///
52 | /// Pinch in gesture.
53 | ///
54 | PinchIn = 256,
55 |
56 | ///
57 | /// Pinch out gesture.
58 | ///
59 | PinchOut = 512
60 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp.Samples/SamplesMenu.cs:
--------------------------------------------------------------------------------
1 | using Spectre.Console;
2 |
3 | namespace Raylib_CSharp.Samples;
4 |
5 | public static class SamplesMenu {
6 |
7 | ///
8 | /// Displays a menu and prompts the user to select a sample to run.
9 | ///
10 | /// An array of ISample objects representing the available samples.
11 | /// A string representing the user's selection.
12 | public static string DisplayMenu(ISample[] samples) {
13 | List options = new List();
14 | options.Add("[red]Exit[/]");
15 | options.Add("[yellow]All[/]");
16 |
17 | foreach (ISample sample in samples) {
18 | options.Add($"[green]{sample.GetType().Name}[/]");
19 | }
20 |
21 | SelectionPrompt consolePrompt = new SelectionPrompt().PageSize(10).MoreChoicesText("[grey](Move up and down to reveal more samples)[/]").AddChoices(options);
22 | AnsiConsole.Write(new FigletText("Raylib-CSharp\nSamples").Color(Color.Purple).Justify(Justify.Center));
23 | AnsiConsole.Write(new Rule("[grey]Select a sample to run[/]").Centered());
24 |
25 | return Markup.Remove(AnsiConsole.Prompt(consolePrompt));
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Unsafe/Spans/Data/SpanData.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Unsafe.Spans.Data;
2 |
3 | public unsafe class SpanData where T : unmanaged {
4 |
5 | private readonly (nint, int) _data;
6 |
7 | ///
8 | /// Initializes a new instance of the SpanData with the specified span.
9 | ///
10 | /// The span to encapsulate.
11 | public SpanData(Span span) {
12 | fixed (T* ptr = span) {
13 | this._data = ((nint) ptr, span.Length);
14 | }
15 | }
16 |
17 | ///
18 | /// Initializes a new instance of the SpanData with the specified pointer and length.
19 | ///
20 | /// The pointer to the data.
21 | /// The length of the span.
22 | public SpanData(T* pointer, int length) {
23 | this._data = ((nint) pointer, length);
24 | }
25 |
26 | ///
27 | /// Retrieves the span encapsulated within the SpanData instance.
28 | ///
29 | /// The span encapsulated within the SpanData instance.
30 | public Span GetSpan() {
31 | return new Span((T*) this._data.Item1, this._data.Item2);
32 | }
33 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Unsafe/Spans/Custom/StringArraySpan.cs:
--------------------------------------------------------------------------------
1 | using Raylib_CSharp.Unsafe.Marshallers;
2 |
3 | namespace Raylib_CSharp.Unsafe.Spans.Custom;
4 |
5 | public readonly unsafe struct StringArraySpan {
6 |
7 | private readonly sbyte** _pointer;
8 |
9 | private readonly int _count;
10 |
11 | ///
12 | /// Initializes a new instance of the StringArraySpan struct with the specified pointer and count.
13 | ///
14 | /// Pointer to the array of strings.
15 | /// Number of strings in the array.
16 | public StringArraySpan(sbyte** pointer, int count) {
17 | this._pointer = pointer;
18 | this._count = count;
19 | }
20 |
21 | ///
22 | /// Gets the string at the specified index.
23 | ///
24 | /// The index of the string to get.
25 | /// The string at the specified index.
26 | public string this[int index] {
27 | get {
28 | if (index >= this._count) {
29 | throw new IndexOutOfRangeException();
30 | }
31 |
32 | return NonFreeUtf8StringMarshaller.ConvertToManaged((nint) this._pointer[index]);
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Unsafe/Marshallers/NonFreeUtf8StringMarshaller.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using System.Runtime.InteropServices.Marshalling;
3 |
4 | namespace Raylib_CSharp.Unsafe.Marshallers;
5 |
6 | [CustomMarshaller(typeof(string), MarshalMode.Default, typeof(NonFreeUtf8StringMarshaller))]
7 | public static class NonFreeUtf8StringMarshaller {
8 |
9 | ///
10 | /// Converts a null-terminated UTF-8 string from the unmanaged memory to a managed string.
11 | ///
12 | /// A pointer to the null-terminated UTF-8 string in unmanaged memory.
13 | /// The managed string representation of the UTF-8 string.
14 | public static string ConvertToManaged(nint unmanaged) {
15 | return Marshal.PtrToStringUTF8(unmanaged) ?? string.Empty;
16 | }
17 |
18 | ///
19 | /// Converts a managed string to a null-terminated UTF-8 string in unmanaged memory.
20 | ///
21 | /// The managed string to be converted.
22 | /// A pointer to the null-terminated UTF-8 string in unmanaged memory.
23 | public static nint ConvertToUnmanaged(string managed) {
24 | return Marshal.StringToCoTaskMemUTF8(managed);
25 | }
26 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Rendering/Gl/FrameBuffer/FramebufferAttachTextureType.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Rendering.Gl.FrameBuffer;
2 |
3 | public enum FramebufferAttachTextureType {
4 |
5 | ///
6 | /// Framebuffer texture attachment type: cubemap, +X side
7 | ///
8 | CubemapPositiveX = 0,
9 |
10 | ///
11 | /// Framebuffer texture attachment type: cubemap, -X side
12 | ///
13 | CubemapNegativeX,
14 |
15 | ///
16 | /// Framebuffer texture attachment type: cubemap, +Y side
17 | ///
18 | CubemapPositiveY,
19 |
20 | ///
21 | /// Framebuffer texture attachment type: cubemap, -Y side
22 | ///
23 | CubemapNegativeY,
24 |
25 | ///
26 | /// Framebuffer texture attachment type: cubemap, +Z side
27 | ///
28 | CubemapPositiveZ,
29 |
30 | ///
31 | /// Framebuffer texture attachment type: cubemap, -Z side
32 | ///
33 | CubemapNegativeZ,
34 |
35 | ///
36 | /// Framebuffer texture attachment type: texture2d
37 | ///
38 | Texture2D = 100,
39 |
40 | ///
41 | /// Framebuffer texture attachment type: renderbuffer
42 | ///
43 | Renderbuffer = 200
44 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Unsafe/Spans/Data/ReadOnlySpanData.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Unsafe.Spans.Data;
2 |
3 | public unsafe class ReadOnlySpanData where T : unmanaged {
4 |
5 | private readonly (nint, int) _data;
6 |
7 | ///
8 | /// Initializes a new instance of the SpanData with the specified span.
9 | ///
10 | /// The span to encapsulate.
11 | public ReadOnlySpanData(ReadOnlySpan span) {
12 | fixed (T* ptr = span) {
13 | this._data = ((nint) ptr, span.Length);
14 | }
15 | }
16 |
17 | ///
18 | /// Initializes a new instance of the SpanData with the specified pointer and length.
19 | ///
20 | /// The pointer to the data.
21 | /// The length of the span.
22 | public ReadOnlySpanData(T* pointer, int length) {
23 | this._data = ((nint) pointer, length);
24 | }
25 |
26 | ///
27 | /// Retrieves the span encapsulated within the SpanData instance.
28 | ///
29 | /// The span encapsulated within the SpanData instance.
30 | public ReadOnlySpan GetSpan() {
31 | return new ReadOnlySpan((T*) this._data.Item1, this._data.Item2);
32 | }
33 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Rendering/Gl/RenderBatch.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 |
3 | namespace Raylib_CSharp.Rendering.Gl;
4 |
5 | [StructLayout(LayoutKind.Sequential)]
6 | public struct RenderBatch {
7 |
8 | ///
9 | /// Number of vertex buffers (multi-buffering support).
10 | ///
11 | public int BufferCount;
12 |
13 | ///
14 | /// Current buffer tracking in case of multi-buffering.
15 | ///
16 | public int CurrentBuffer;
17 |
18 | ///
19 | /// Dynamic buffer(s) for vertex data.
20 | ///
21 | public unsafe VertexBuffer* VertexBufferPtr;
22 |
23 | ///
24 | public unsafe Span VertexBuffer => new(this.VertexBufferPtr, this.BufferCount);
25 |
26 | ///
27 | /// Draw calls array, depends on textureId.
28 | ///
29 | public unsafe DrawCall* DrawsPtr;
30 |
31 | ///
32 | public unsafe Span Draws => new(this.DrawsPtr, this.DrawCounter);
33 |
34 | ///
35 | /// Draw calls counter.
36 | ///
37 | public int DrawCounter;
38 |
39 | ///
40 | /// Current depth value for next draw.
41 | ///
42 | public float CurrentDepth;
43 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Rendering/Gl/FrameBuffer/FramebufferAttachType.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Rendering.Gl.FrameBuffer;
2 |
3 | public enum FramebufferAttachType {
4 |
5 | ///
6 | /// Framebuffer attachment type: color 0
7 | ///
8 | ColorChannel0 = 0,
9 |
10 | ///
11 | /// Framebuffer attachment type: color 1
12 | ///
13 | ColorChannel1,
14 |
15 | ///
16 | /// Framebuffer attachment type: color 2
17 | ///
18 | ColorChannel2,
19 |
20 | ///
21 | /// Framebuffer attachment type: color 3
22 | ///
23 | ColorChannel3,
24 |
25 | ///
26 | /// Framebuffer attachment type: color 4
27 | ///
28 | ColorChannel4,
29 |
30 | ///
31 | /// Framebuffer attachment type: color 5
32 | ///
33 | ColorChannel5,
34 |
35 | ///
36 | /// Framebuffer attachment type: color 6
37 | ///
38 | ColorChannel6,
39 |
40 | ///
41 | /// Framebuffer attachment type: color 7
42 | ///
43 | ColorChannel7,
44 |
45 | ///
46 | /// Framebuffer attachment type: depth
47 | ///
48 | Depth = 100,
49 |
50 | ///
51 | /// Framebuffer attachment type: stencil
52 | ///
53 | Stencil = 200
54 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Unsafe/Spans/Custom/FixedArraySpan.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Unsafe.Spans.Custom;
2 |
3 | public readonly unsafe struct FixedArraySpan where T : unmanaged {
4 |
5 | private readonly T** _pointer;
6 |
7 | private readonly int _length;
8 |
9 | private readonly int _count;
10 |
11 | ///
12 | /// Initializes a new instance of the FixedArraySpan class with the specified pointer, length, and count.
13 | ///
14 | /// Pointer to the array.
15 | /// Length of the array.
16 | /// Number of elements in each sub-array.
17 | public FixedArraySpan(T** pointer, int length, int count) {
18 | this._pointer = pointer;
19 | this._length = length;
20 | this._count = count;
21 | }
22 |
23 | ///
24 | /// Gets a read-only span representing the sub-array at the specified index.
25 | ///
26 | /// The index of the sub-array.
27 | /// A read-only span representing the sub-array.
28 | public Span this[int index] {
29 | get {
30 | if (index >= this._length) {
31 | throw new IndexOutOfRangeException();
32 | }
33 |
34 | return new(this._pointer[index], this._count);
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Interact/MouseCursor.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Interact;
2 |
3 | public enum MouseCursor {
4 |
5 | ///
6 | /// Default pointer shape.
7 | ///
8 | Default = 0,
9 |
10 | ///
11 | /// Arrow shape.
12 | ///
13 | Arrow = 1,
14 |
15 | ///
16 | /// Text writing cursor shape.
17 | ///
18 | IBeam = 2,
19 |
20 | ///
21 | /// Cross shape.
22 | ///
23 | Crosshair = 3,
24 |
25 | ///
26 | /// Pointing hand cursor.
27 | ///
28 | PointingHand = 4,
29 |
30 | ///
31 | /// Horizontal resize/move arrow shape.
32 | ///
33 | ResizeEw = 5,
34 |
35 | ///
36 | /// Vertical resize/move arrow shape.
37 | ///
38 | ResizeNs = 6,
39 |
40 | ///
41 | /// Top-left to bottom-right diagonal resize/move arrow shape.
42 | ///
43 | ResizeNwse = 7,
44 |
45 | ///
46 | /// The top-right to bottom-left diagonal resize/move arrow shape.
47 | ///
48 | ResizeNesw = 8,
49 |
50 | ///
51 | /// The omnidirectional resize/move cursor shape.
52 | ///
53 | ResizeAll = 9,
54 |
55 | ///
56 | /// The operation-not-allowed shape.
57 | ///
58 | NotAllowed = 10
59 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Automations/AutomationEventList.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Raylib_CSharp.Apis;
3 |
4 | namespace Raylib_CSharp.Automations;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct AutomationEventList {
8 |
9 | ///
10 | /// Events max entries (MAX_AUTOMATION_EVENTS).
11 | ///
12 | public uint Capacity;
13 |
14 | ///
15 | /// Events entries count.
16 | ///
17 | public uint Count;
18 |
19 | ///
20 | /// Events entries.
21 | ///
22 | public unsafe AutomationEvent* EventsPtr;
23 |
24 | ///
25 | public unsafe Span Events => new(this.EventsPtr, (int)this.Capacity);
26 |
27 | ///
28 | public static AutomationEventList Load(string fileName) {
29 | return RaylibApi.LoadAutomationEventList(fileName);
30 | }
31 |
32 | ///
33 | public void Unload() {
34 | RaylibApi.UnloadAutomationEventList(this);
35 | }
36 |
37 | ///
38 | public bool Export(string fileName) {
39 | return RaylibApi.ExportAutomationEventList(this, fileName);
40 | }
41 |
42 | ///
43 | public void Set() {
44 | RaylibApi.SetAutomationEventList(ref this);
45 | }
46 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Unsafe/FixedString.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Raylib_CSharp.Unsafe.Marshallers;
3 |
4 | namespace Raylib_CSharp.Unsafe;
5 |
6 | public static class FixedString {
7 |
8 | ///
9 | /// Returns the value of a fixed-length string stored in unmanaged memory.
10 | ///
11 | /// A pointer to the fixed-length string in unmanaged memory.
12 | /// The value of the fixed-length string.
13 | public static unsafe string GetValue(sbyte* src) {
14 | return NonFreeUtf8StringMarshaller.ConvertToManaged((IntPtr) src);
15 | }
16 |
17 | ///
18 | /// Sets the value of a fixed-length string stored in unmanaged memory.
19 | ///
20 | /// A pointer to the fixed-length string in unmanaged memory where the value will be set.
21 | /// The maximum length of the fixed-length string.
22 | /// The string value to be set in the fixed-length string.
23 | public static unsafe void SetValue(sbyte* dst, int dstLength, string? src) {
24 | sbyte* unmanagedValue = (sbyte*) NonFreeUtf8StringMarshaller.ConvertToUnmanaged(src!);
25 |
26 | Buffer.MemoryCopy(unmanagedValue, dst, dstLength, Math.Min(dstLength + 1, src?.Length ?? 0));
27 |
28 | if (src == null) {
29 | dst[0] = 0;
30 | }
31 |
32 | Marshal.FreeCoTaskMem((nint) unmanagedValue);
33 | }
34 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp.Test/NativeBindingsContext.cs:
--------------------------------------------------------------------------------
1 | using OpenTK;
2 | using Raylib_CSharp.Rendering.Gl.Contexts;
3 |
4 | namespace Raylib_CSharp.Test;
5 |
6 | public class NativeBindingsContext : IDisposable, IBindingsContext {
7 |
8 | private NativeGlContext _context;
9 |
10 | public bool HasDisposed { get; private set; }
11 |
12 | ///
13 | /// Represents a context for native bindings in OpenGL.
14 | ///
15 | public NativeBindingsContext() {
16 | this._context = new NativeGlContext();
17 | }
18 |
19 | public nint GetProcAddress(string procName) {
20 | return this._context.GetProcAddress(procName);
21 | }
22 |
23 | ///
24 | /// Disposes of the object, allowing for proper resource cleanup and finalization.
25 | ///
26 | public void Dispose() {
27 | if (this.HasDisposed) return;
28 |
29 | this.Dispose(true);
30 | GC.SuppressFinalize(this);
31 | this.HasDisposed = true;
32 | }
33 |
34 | ///
35 | /// Releases the managed resources used by the object (disposing), and optionally releases the unmanaged.
36 | /// resources (not disposing).
37 | ///
38 | /// A boolean value indicating whether the method is being called from, dispose method directly (true) or from the finalizer (false).
39 | protected void Dispose(bool disposing) {
40 | if (disposing) {
41 | this._context.Dispose();
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Automations/AutomationEvent.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Raylib_CSharp.Apis;
3 |
4 | namespace Raylib_CSharp.Automations;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct AutomationEvent {
8 |
9 | ///
10 | /// Event frame.
11 | ///
12 | public uint Frame;
13 |
14 | ///
15 | /// Event type (AutomationEventType).
16 | ///
17 | public AutomationEventType Type;
18 |
19 | ///
20 | /// Event parameters (if required).
21 | ///
22 | public unsafe fixed int ParamsPtr[4];
23 |
24 | ///
25 | public unsafe Span Params {
26 | get {
27 | fixed (int* paramsPtr = this.ParamsPtr) {
28 | return new Span(paramsPtr, 4);
29 | }
30 | }
31 | }
32 |
33 | ///
34 | public static void SetBaseFrame(int frame) {
35 | RaylibApi.SetAutomationEventBaseFrame(frame);
36 | }
37 |
38 | ///
39 | public static void StartRecording() {
40 | RaylibApi.StartAutomationEventRecording();
41 | }
42 |
43 | ///
44 | public static void StopRecording() {
45 | RaylibApi.StopAutomationEventRecording();
46 | }
47 |
48 | ///
49 | public void Play() {
50 | RaylibApi.PlayAutomationEvent(this);
51 | }
52 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Materials/MaterialMapIndex.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Materials;
2 |
3 | public enum MaterialMapIndex {
4 |
5 | ///
6 | /// Albedo material (same as: MATERIAL_MAP_DIFFUSE).
7 | ///
8 | Albedo = 0,
9 |
10 | ///
11 | /// Metalness material (same as: MATERIAL_MAP_SPECULAR).
12 | ///
13 | Metalness,
14 |
15 | ///
16 | /// Normal material.
17 | ///
18 | Normal,
19 |
20 | ///
21 | /// Roughness material.
22 | ///
23 | Roughness,
24 |
25 | ///
26 | /// Ambient occlusion material.
27 | ///
28 | Occlusion,
29 |
30 | ///
31 | /// Emission material.
32 | ///
33 | Emission,
34 |
35 | ///
36 | /// Heightmap material.
37 | ///
38 | Height,
39 |
40 | ///
41 | /// Cubemap material (NOTE: Uses GL_TEXTURE_CUBE_MAP).
42 | ///
43 | Cubemap,
44 |
45 | ///
46 | /// Irradiance material (NOTE: Uses GL_TEXTURE_CUBE_MAP).
47 | ///
48 | Irradiance,
49 |
50 | ///
51 | /// Prefilter material (NOTE: Uses GL_TEXTURE_CUBE_MAP).
52 | ///
53 | Prefilter,
54 |
55 | ///
56 | /// Brdf material.
57 | ///
58 | Brdf,
59 |
60 | ///
61 | /// Diffuse material (same as: MATERIAL_MAP_ALBEDO).
62 | ///
63 | Diffuse = Albedo,
64 |
65 | ///
66 | /// Specular material (same as: MATERIAL_MAP_METALNESS).
67 | ///
68 | Specular = Metalness
69 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp.Samples/Program.cs:
--------------------------------------------------------------------------------
1 | using Raylib_CSharp.Samples;
2 | using Raylib_CSharp.Samples.Core;
3 | using Spectre.Console;
4 |
5 | ISample[] samples = [
6 | new BasicWindow(),
7 | new CustomLogger(),
8 | new Pong(),
9 | new SpinningAroundADiamond()
10 | ];
11 |
12 | string selection = args.Length == 0 ? SamplesMenu.DisplayMenu(samples) : args[0];
13 |
14 | switch (selection) {
15 | case "Exit":
16 | Exit();
17 | break;
18 |
19 | case "All":
20 | RunAll(samples);
21 | break;
22 |
23 | default:
24 | Run(selection, samples);
25 | break;
26 | }
27 |
28 | return;
29 |
30 | void Exit() {
31 | AnsiConsole.MarkupLine("Goodbye!");
32 | Thread.Sleep(1000); // wait a bit for the user to read the message
33 | Environment.Exit(0);
34 | }
35 |
36 | void RunAll(IEnumerable samplesToRun) {
37 | foreach (ISample sample in samplesToRun) {
38 | using (sample) {
39 | AnsiConsole.MarkupLine($"Running [bold]{sample.GetType().Name}[/]");
40 | Thread.Sleep(1000); // wait a bit for the user to read the message
41 | sample.Run();
42 | }
43 | }
44 | }
45 |
46 | void Run(string selectionToRun, IEnumerable samplesToRun) {
47 | ISample? sample = samplesToRun.FirstOrDefault(s => s.GetType().Name.Equals(selectionToRun, StringComparison.OrdinalIgnoreCase));
48 |
49 | if (sample == null) {
50 | AnsiConsole.MarkupLine($"[red]Sample not found: {selectionToRun}...[/]");
51 | Thread.Sleep(1000); // wait a bit for the user to read the message
52 | return;
53 | }
54 |
55 | using (sample) {
56 | AnsiConsole.MarkupLine($"Running [bold]{sample.GetType().Name}[/]");
57 | Thread.Sleep(1000); // wait a bit for the user to read the message
58 | sample.Run();
59 | }
60 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Raylib-CSharp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | net8.0
6 | Raylib_CSharp
7 | enable
8 | enable
9 | true
10 |
11 |
12 |
13 |
14 | Raylib-CSharp
15 | MrScautHD
16 | 4.1.8
17 | true
18 | true
19 | $(NoWarn);1591
20 | A fast, Cross-platform Raylib C# Wrapper.
21 | https://www.nuget.org/packages/Raylib-CSharp
22 | https://github.com/MrScautHD/Raylib-CSharp/blob/main/LICENSE
23 | https://github.com/MrScautHD/Raylib-CSharp
24 | Raylib, Raylib-CSharp, C#, Modern, Fast, Managed-classes, dotnet, .Net8, C#12
25 | icon.png
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | runtimes/%(RecursiveDir)/%(Filename)%(Extension)
37 | PreserveNewest
38 | true
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Vr/VrStereoConfig.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using System.Runtime.InteropServices;
3 | using Raylib_CSharp.Apis;
4 |
5 | namespace Raylib_CSharp.Vr;
6 |
7 | [StructLayout(LayoutKind.Sequential)]
8 | public struct VrStereoConfig {
9 |
10 | ///
11 | /// VR projection matrices (per eye).
12 | ///
13 | public Matrix4x4 Projection1;
14 |
15 | ///
16 | /// VR projection matrices (per eye).
17 | ///
18 | public Matrix4x4 Projection2;
19 |
20 | ///
21 | /// VR view offset matrices (per eye).
22 | ///
23 | public Matrix4x4 ViewOffset1;
24 |
25 | ///
26 | /// VR view offset matrices (per eye).
27 | ///
28 | public Matrix4x4 ViewOffset2;
29 |
30 | ///
31 | /// VR left lens center.
32 | ///
33 | public Vector2 LeftLensCenter;
34 |
35 | ///
36 | /// VR right lens center.
37 | ///
38 | public Vector2 RightLensCenter;
39 |
40 | ///
41 | /// VR left screen center.
42 | ///
43 | public Vector2 LeftScreenCenter;
44 |
45 | ///
46 | /// VR right screen center.
47 | ///
48 | public Vector2 RightScreenCenter;
49 |
50 | ///
51 | /// VR distortion scale.
52 | ///
53 | public Vector2 Scale;
54 |
55 | ///
56 | /// VR distortion scale in.
57 | ///
58 | public Vector2 ScaleIn;
59 |
60 | ///
61 | public static VrStereoConfig Load(VrDeviceInfo device) {
62 | return RaylibApi.LoadVrStereoConfig(device);
63 | }
64 |
65 | ///
66 | public void Unload() {
67 | RaylibApi.UnloadVrStereoConfig(this);
68 | }
69 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Camera/Cam2D/Camera2D.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using System.Runtime.InteropServices;
3 | using Raylib_CSharp.Apis;
4 |
5 | namespace Raylib_CSharp.Camera.Cam2D;
6 |
7 | [StructLayout(LayoutKind.Sequential)]
8 | public struct Camera2D {
9 |
10 | ///
11 | /// Camera offset (displacement from target).
12 | ///
13 | public Vector2 Offset;
14 |
15 | ///
16 | /// Camera target (rotation and zoom origin).
17 | ///
18 | public Vector2 Target;
19 |
20 | ///
21 | /// Camera rotation in degrees.
22 | ///
23 | public float Rotation;
24 |
25 | ///
26 | /// Camera zoom (scaling), should be 1.0f by default.
27 | ///
28 | public float Zoom;
29 |
30 | ///
31 | /// Camera2D, defines position/orientation in 2d space.
32 | ///
33 | /// Offset position of the camera.
34 | /// Target point of the camera.
35 | /// Rotation angle of the camera.
36 | /// Zoom level of the camera.
37 | public Camera2D(Vector2 offset, Vector2 target, float rotation, float zoom) {
38 | this.Offset = offset;
39 | this.Target = target;
40 | this.Rotation = rotation;
41 | this.Zoom = zoom;
42 | }
43 |
44 | ///
45 | public Vector2 GetScreenToWorld(Vector2 position) {
46 | return RaylibApi.GetScreenToWorld2D(position, this);
47 | }
48 |
49 | ///
50 | public Vector2 GetWorldToScreen(Vector2 position) {
51 | return RaylibApi.GetWorldToScreen2D(position, this);
52 | }
53 |
54 | ///
55 | public Matrix4x4 GetMatrix() {
56 | return RaylibApi.GetCameraMatrix2D(this);
57 | }
58 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Logging/Logger.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 | using System.Runtime.InteropServices;
3 | using Raylib_CSharp.Apis;
4 |
5 | namespace Raylib_CSharp.Logging;
6 |
7 | public static class Logger {
8 |
9 | public delegate bool OnMessage(TraceLogLevel logLevel, string text);
10 | public static event OnMessage? Message;
11 |
12 | private static StringFormatter? _formatter;
13 |
14 | ///
15 | /// Initializes the logger by setting the trace log callback.
16 | ///
17 | public static unsafe void Init() {
18 | _formatter = new StringFormatter();
19 | RaylibApi.SetTraceLogCallback(&TraceLogCallback);
20 | }
21 |
22 | ///
23 | public static void TraceLog(TraceLogLevel logLevel, string text) {
24 | RaylibApi.TraceLog(logLevel, text);
25 | }
26 |
27 | ///
28 | public static void SetTraceLogLevel(TraceLogLevel logLevel) {
29 | RaylibApi.SetTraceLogLevel(logLevel);
30 | }
31 |
32 | ///
33 | /// Callback method that is called whenever a new log message is generated.
34 | ///
35 | /// The level of the log message.
36 | /// The log message.
37 | /// Additional arguments.
38 | [UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
39 | private static void TraceLogCallback(int logLevel, nint text, nint args) {
40 | string msg = _formatter!.GetMessage(text, args);
41 |
42 | OnMessage? message = Message;
43 |
44 | if (message != null) {
45 | if (message.Invoke((TraceLogLevel) logLevel, msg)) {
46 | return;
47 | }
48 | }
49 | }
50 |
51 | ///
52 | /// Destroys the logger (sets the trace log callback to null).
53 | ///
54 | public static unsafe void Destroy() {
55 | Message = null;
56 | RaylibApi.SetTraceLogCallback(null);
57 | }
58 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Vr/VrDeviceInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 |
3 | namespace Raylib_CSharp.Vr;
4 |
5 | [StructLayout(LayoutKind.Sequential)]
6 | public struct VrDeviceInfo {
7 |
8 | ///
9 | /// Horizontal resolution in pixels.
10 | ///
11 | public int HResolution;
12 |
13 | ///
14 | /// Vertical resolution in pixels.
15 | ///
16 | public int VResolution;
17 |
18 | ///
19 | /// Horizontal size in meters.
20 | ///
21 | public float HScreenSize;
22 |
23 | ///
24 | /// Vertical size in meters.
25 | ///
26 | public float VScreenSize;
27 |
28 | ///
29 | /// Distance between eye and display in meters.
30 | ///
31 | public float EyeToScreenDistance;
32 |
33 | ///
34 | /// Lens separation distance in meters.
35 | ///
36 | public float LensSeparationDistance;
37 |
38 | ///
39 | /// IPD (distance between pupils) in meters.
40 | ///
41 | public float InterpupillaryDistance;
42 |
43 | ///
44 | /// Lens distortion constant parameters.
45 | ///
46 | public unsafe fixed float LensDistortionValuesPtr[4];
47 |
48 | ///
49 | public unsafe Span LensDistortionValues {
50 | get {
51 | fixed (float* lensDistortionValues = this.LensDistortionValuesPtr) {
52 | return new(lensDistortionValues, 4);
53 | }
54 | }
55 | }
56 |
57 | ///
58 | /// Chromatic aberration correction parameters.
59 | ///
60 | public unsafe fixed float ChromaAbCorrectionPtr[4];
61 |
62 | ///
63 | public unsafe Span ChromaAbCorrection {
64 | get {
65 | fixed (float* chromaAbCorrection = this.ChromaAbCorrectionPtr) {
66 | return new(chromaAbCorrection, 4);
67 | }
68 | }
69 | }
70 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Rendering/Gl/Contexts/NativeGlContext.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 |
3 | namespace Raylib_CSharp.Rendering.Gl.Contexts;
4 |
5 | public class NativeGlContext : IGlContext, IDisposable {
6 |
7 | public bool HasDisposed { get; private set; }
8 |
9 | private IGlContext _context;
10 |
11 | ///
12 | /// Represents a native OpenGL context (Use it for bindings like OpenTK...).
13 | ///
14 | public NativeGlContext() {
15 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
16 | this._context = new WinGlContext();
17 | }
18 | else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
19 | this._context = new LinuxGlContext();
20 | }
21 | else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
22 | this._context = new MacOsGlContext();
23 | }
24 | else {
25 | throw new PlatformNotSupportedException("Platform is not supported!");
26 | }
27 | }
28 |
29 | public nint GetProcAddress(string procName) {
30 | return this._context.GetProcAddress(procName);
31 | }
32 |
33 | ///
34 | /// Disposes of the object, allowing for proper resource cleanup and finalization.
35 | ///
36 | public void Dispose() {
37 | if (this.HasDisposed) return;
38 |
39 | this.Dispose(true);
40 | GC.SuppressFinalize(this);
41 | this.HasDisposed = true;
42 | }
43 |
44 | ///
45 | /// Releases the managed resources used by the object (disposing), and optionally releases the unmanaged.
46 | /// resources (not disposing).
47 | ///
48 | /// A boolean value indicating whether the method is being called from, dispose method directly (true) or from the finalizer (false).
49 | protected virtual void Dispose(bool disposing) {
50 | if (disposing) {
51 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
52 | ((WinGlContext) this._context).Dispose();
53 | }
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Transformations/Rectangle.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace Raylib_CSharp.Transformations;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct Rectangle {
8 |
9 | ///
10 | /// Rectangle top-left corner position x.
11 | ///
12 | public float X;
13 |
14 | ///
15 | /// Rectangle top-left corner position y.
16 | ///
17 | public float Y;
18 |
19 | ///
20 | /// Rectangle width.
21 | ///
22 | public float Width;
23 |
24 | ///
25 | /// Rectangle height.
26 | ///
27 | public float Height;
28 |
29 | ///
30 | /// Rectangle, 4 components.
31 | ///
32 | /// The x-coordinate of the rectangle.
33 | /// The y-coordinate of the rectangle.
34 | /// The width of the rectangle.
35 | /// The height of the rectangle.
36 | public Rectangle(float x, float y, float width, float height) {
37 | this.X = x;
38 | this.Y = y;
39 | this.Width = width;
40 | this.Height = height;
41 | }
42 |
43 | ///
44 | /// Gets or sets the position of the top-left corner of the rectangle.
45 | ///
46 | /// The position of the top-left corner of the rectangle.
47 | public Vector2 Position {
48 | get => new Vector2(this.X, this.Y);
49 | set {
50 | this.X = value.X;
51 | this.Y = value.Y;
52 | }
53 | }
54 |
55 | ///
56 | /// Gets or sets the size of the rectangle.
57 | ///
58 | /// A Vector2 representing the width and height of the rectangle.
59 | public Vector2 Size {
60 | get => new Vector2(this.Width, this.Height);
61 | set {
62 | this.Width = value.X;
63 | this.Height = value.Y;
64 | }
65 | }
66 |
67 | public override string ToString() {
68 | return $"X:{this.X} Y:{this.Y} Width:{this.Width} Height:{this.Height}";
69 | }
70 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Windowing/ConfigFlags.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Windowing;
2 |
3 | [Flags]
4 | public enum ConfigFlags : uint {
5 |
6 | ///
7 | /// Set to try enabling V-Sync on GPU.
8 | ///
9 | VSyncHint = 0x00000040,
10 |
11 | ///
12 | /// Set to run program in fullscreen.
13 | ///
14 | FullscreenMode = 0x00000002,
15 |
16 | ///
17 | /// Set to allow resizable window.
18 | ///
19 | ResizableWindow = 0x00000004,
20 |
21 | ///
22 | /// Set to disable window decoration (frame and buttons).
23 | ///
24 | UndecoratedWindow = 0x00000008,
25 |
26 | ///
27 | /// Set to hide window.
28 | ///
29 | HiddenWindow = 0x00000080,
30 |
31 | ///
32 | /// Set to minimize window (iconify).
33 | ///
34 | MinimizedWindow = 0x00000200,
35 |
36 | ///
37 | /// Set to maximize window (expanded to monitor).
38 | ///
39 | MaximizedWindow = 0x00000400,
40 |
41 | ///
42 | /// Set to window non focused.
43 | ///
44 | UnfocusedWindow = 0x00000800,
45 |
46 | ///
47 | /// Set to window always on top.
48 | ///
49 | TopmostWindow = 0x00001000,
50 |
51 | ///
52 | /// Set to allow windows running while minimized.
53 | ///
54 | AlwaysRunWindow = 0x00000100,
55 |
56 | ///
57 | /// Set to allow transparent framebuffer.
58 | ///
59 | TransparentWindow = 0x00000010,
60 |
61 | ///
62 | /// Set to support HighDPI.
63 | ///
64 | HighDpiWindow = 0x00002000,
65 |
66 | ///
67 | /// Set to support mouse passthrough, only supported when FLAG_WINDOW_UNDECORATED.
68 | ///
69 | MousePassthroughWindow = 0x00004000,
70 |
71 | ///
72 | /// Set to run program in borderless windowed mode.
73 | ///
74 | BorderlessWindowMode = 0x00008000,
75 |
76 | ///
77 | /// Set to try enabling MSAA 4X.
78 | ///
79 | Msaa4XHint = 0x00000020,
80 |
81 | ///
82 | /// Set to try enabling interlaced video format (for V3D).
83 | ///
84 | InterlacedHint = 0x00010000
85 | }
--------------------------------------------------------------------------------
/Raylib-CSharp.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.9.34728.123
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Raylib-CSharp", "src\Raylib-CSharp\Raylib-CSharp.csproj", "{06C3AD87-19F1-4E57-909F-7DA12CB12C2E}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Raylib-CSharp.Test", "src\Raylib-CSharp.Test\Raylib-CSharp.Test.csproj", "{FFB46B6C-6508-45E9-99EF-C7321EB8C2F4}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6A01BA31-440F-4336-93B8-E50DB5E877A9}"
11 | ProjectSection(SolutionItems) = preProject
12 | .editorconfig = .editorconfig
13 | EndProjectSection
14 | EndProject
15 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Raylib-CSharp.Samples", "src\Raylib-CSharp.Samples\Raylib-CSharp.Samples.csproj", "{3260131D-2B07-44D5-B829-F2BB5BC2058B}"
16 | EndProject
17 | Global
18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
19 | Debug|Any CPU = Debug|Any CPU
20 | Release|Any CPU = Release|Any CPU
21 | EndGlobalSection
22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
23 | {06C3AD87-19F1-4E57-909F-7DA12CB12C2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24 | {06C3AD87-19F1-4E57-909F-7DA12CB12C2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
25 | {06C3AD87-19F1-4E57-909F-7DA12CB12C2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
26 | {06C3AD87-19F1-4E57-909F-7DA12CB12C2E}.Release|Any CPU.Build.0 = Release|Any CPU
27 | {FFB46B6C-6508-45E9-99EF-C7321EB8C2F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28 | {FFB46B6C-6508-45E9-99EF-C7321EB8C2F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
29 | {FFB46B6C-6508-45E9-99EF-C7321EB8C2F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
30 | {FFB46B6C-6508-45E9-99EF-C7321EB8C2F4}.Release|Any CPU.Build.0 = Release|Any CPU
31 | {3260131D-2B07-44D5-B829-F2BB5BC2058B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32 | {3260131D-2B07-44D5-B829-F2BB5BC2058B}.Debug|Any CPU.Build.0 = Debug|Any CPU
33 | {3260131D-2B07-44D5-B829-F2BB5BC2058B}.Release|Any CPU.ActiveCfg = Release|Any CPU
34 | {3260131D-2B07-44D5-B829-F2BB5BC2058B}.Release|Any CPU.Build.0 = Release|Any CPU
35 | EndGlobalSection
36 | GlobalSection(SolutionProperties) = preSolution
37 | HideSolutionNode = FALSE
38 | EndGlobalSection
39 | EndGlobal
40 |
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Raylib.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 | using Raylib_CSharp.Windowing;
3 | using Raylib_CSharp.Apis;
4 |
5 | [assembly: DisableRuntimeMarshalling]
6 |
7 | namespace Raylib_CSharp;
8 |
9 | public static class Raylib {
10 |
11 | public const string Name = "raylib";
12 |
13 | public static readonly Version Version = new(5, 0, 0);
14 | public static readonly Version RlVersion = new(5, 5, 0);
15 |
16 | ///
17 | public static void TakeScreenshot(string path) {
18 | RaylibApi.TakeScreenshot(path);
19 | }
20 |
21 | ///
22 | public static void SetConfigFlags(ConfigFlags flags) {
23 | RaylibApi.SetConfigFlags(flags);
24 | }
25 |
26 | ///
27 | public static void OpenURL(string path) {
28 | RaylibApi.OpenURL(path);
29 | }
30 |
31 | ///
32 | public static void SetRandomSeed(uint seed) {
33 | RaylibApi.SetRandomSeed(seed);
34 | }
35 |
36 | ///
37 | public static int GetRandomValue(int min, int max) {
38 | return RaylibApi.GetRandomValue(min, max);
39 | }
40 |
41 | ///
42 | public static unsafe ReadOnlySpan LoadRandomSequence(int count, int min, int max) {
43 | return new ReadOnlySpan(RaylibApi.LoadRandomSequence(count, min, max), count);
44 | }
45 |
46 | ///
47 | public static unsafe void UnloadRandomSequence(ReadOnlySpan sequence) {
48 | fixed (int* sequencePtr = sequence) {
49 | RaylibApi.UnloadRandomSequence(sequencePtr);
50 | }
51 | }
52 |
53 | ///
54 | public static unsafe T* MemAlloc(int size) where T : unmanaged {
55 | return (T*)RaylibApi.MemAlloc(size * sizeof(T));
56 | }
57 |
58 | ///
59 | public static unsafe T* MemRealloc(T* ptr, int size) where T : unmanaged {
60 | return (T*)RaylibApi.MemRealloc((nint)ptr, size * sizeof(T));
61 | }
62 |
63 | ///
64 | public static unsafe void MemFree(T* ptr) where T : unmanaged {
65 | RaylibApi.MemFree((nint)ptr);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/Raylib-CSharp.Samples/Core/CustomLogger.cs:
--------------------------------------------------------------------------------
1 | using Raylib_CSharp.Colors;
2 | using Raylib_CSharp.Logging;
3 | using Raylib_CSharp.Rendering;
4 | using Raylib_CSharp.Windowing;
5 |
6 | namespace Raylib_CSharp.Samples.Core;
7 |
8 | public class CustomLogger : ISample {
9 |
10 | public void Run() {
11 | Logger.Init();
12 | Logger.Message += this.Custom;
13 |
14 | Window.Init(1280, 720, "Custom Logger");
15 |
16 | while (!Window.ShouldClose()) {
17 | Graphics.BeginDrawing();
18 | Graphics.ClearBackground(Color.SkyBlue);
19 |
20 | Graphics.DrawText("Custom Logger!", 10, 10, 20, Color.White);
21 |
22 | Graphics.EndDrawing();
23 | }
24 | }
25 |
26 | ///
27 | /// Writes a custom log message with the specified log level and text.
28 | ///
29 | /// The log level of the message.
30 | /// The text of the log message.
31 | /// True if the log message was written successfully, false otherwise.
32 | private bool Custom(TraceLogLevel level, string text) {
33 | switch (level) {
34 |
35 | case TraceLogLevel.Debug:
36 | Console.ForegroundColor = ConsoleColor.Gray;
37 | Console.WriteLine(text);
38 | Console.ResetColor();
39 | return true;
40 |
41 | case TraceLogLevel.Info:
42 | Console.ForegroundColor = ConsoleColor.Cyan;
43 | Console.WriteLine(text);
44 | Console.ResetColor();
45 | return true;
46 |
47 | case TraceLogLevel.Warning:
48 | Console.ForegroundColor = ConsoleColor.Yellow;
49 | Console.WriteLine(text);
50 | Console.ResetColor();
51 | return true;
52 |
53 | case TraceLogLevel.Error:
54 | Console.ForegroundColor = ConsoleColor.Red;
55 | Console.WriteLine(text);
56 | Console.ResetColor();
57 | return true;
58 |
59 | case TraceLogLevel.Fatal:
60 | Console.ForegroundColor = ConsoleColor.Red;
61 | Console.WriteLine(text);
62 | Console.ResetColor();
63 | return true;
64 | }
65 |
66 | return false;
67 | }
68 |
69 | public void Dispose() {
70 | Window.Close();
71 | Logger.Destroy();
72 | }
73 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Rendering/Gl/VertexBuffer.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using System.Runtime.InteropServices;
3 | using Raylib_CSharp.Colors;
4 |
5 | namespace Raylib_CSharp.Rendering.Gl;
6 |
7 | [StructLayout(LayoutKind.Sequential)]
8 | public struct VertexBuffer {
9 |
10 | ///
11 | /// Number of elements in the buffer (QUADS).
12 | ///
13 | public int ElementCount;
14 |
15 | ///
16 | /// Vertex position (XYZ - 3 components per vertex) (shader-location = 0).
17 | ///
18 | public unsafe float* VerticesPtr;
19 |
20 | ///
21 | public unsafe Span Vertices => new(this.VerticesPtr, this.ElementCount * 4);
22 |
23 | ///
24 | /// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1).
25 | ///
26 | public unsafe float* TexCoordsPtr;
27 |
28 | ///
29 | public unsafe Span TexCoords => new(this.TexCoordsPtr, this.ElementCount * 4);
30 |
31 | ///
32 | /// Vertex normals (XYZ - 3 components per vertex) (shader-location = 2).
33 | ///
34 | public unsafe float* NormalsPtr;
35 |
36 | ///
37 | public unsafe Span Normals => new(this.NormalsPtr, this.ElementCount * 3);
38 |
39 | ///
40 | /// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3).
41 | ///
42 | public unsafe byte* ColorsPtr;
43 |
44 | ///
45 | public unsafe Span Colors => new(this.ColorsPtr, this.ElementCount * 4);
46 |
47 | ///
48 | /// Vertex indices (in case vertex data comes indexed) (6 indices per quad).
49 | ///
50 | public unsafe uint* IndicesPtr;
51 |
52 | ///
53 | public unsafe Span Indices => new(this.IndicesPtr, this.ElementCount * 6);
54 |
55 | ///
56 | /// OpenGL Vertex Array Object id.
57 | ///
58 | public uint VaoId;
59 |
60 | ///
61 | /// OpenGL Vertex Buffer Objects id (5 types of vertex data).
62 | ///
63 | public unsafe fixed uint VboIdPtr[5];
64 |
65 | ///
66 | public unsafe Span VboId {
67 | get {
68 | fixed (uint* idPtr = this.VboIdPtr) {
69 | return new(idPtr, 4);
70 | }
71 | }
72 | }
73 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Interact/GamepadButton.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Interact;
2 |
3 | public enum GamepadButton {
4 |
5 | ///
6 | /// Unknown button, just for error checking.
7 | ///
8 | Unknown = 0,
9 |
10 | ///
11 | /// Gamepad left DPAD up button.
12 | ///
13 | LeftFaceUp,
14 |
15 | ///
16 | /// Gamepad left DPAD right button.
17 | ///
18 | LeftFaceRight,
19 |
20 | ///
21 | /// Gamepad left DPAD down button.
22 | ///
23 | LeftFaceDown,
24 |
25 | ///
26 | /// Gamepad left DPAD left button.
27 | ///
28 | LeftFaceLeft,
29 |
30 | ///
31 | /// Gamepad right button up (i.e. PS3: Triangle, Xbox: Y).
32 | ///
33 | RightFaceUp,
34 |
35 | ///
36 | /// Gamepad right button right (i.e. PS3: Circle, Xbox: B).
37 | ///
38 | RightFaceRight,
39 |
40 | ///
41 | /// Gamepad right button down (i.e. PS3: Cross, Xbox: A).
42 | ///
43 | RightFaceDown,
44 |
45 | ///
46 | /// Gamepad right button left (i.e. PS3: Square, Xbox: X).
47 | ///
48 | RightFaceLeft,
49 |
50 | ///
51 | /// Gamepad top/back trigger left (first), it could be a trailing button.
52 | ///
53 | LeftTrigger1,
54 |
55 | ///
56 | /// Gamepad top/back trigger left (second), it could be a trailing button.
57 | ///
58 | LeftTrigger2,
59 |
60 | ///
61 | /// Gamepad top/back trigger right (first), it could be a trailing button.
62 | ///
63 | RightTrigger1,
64 |
65 | ///
66 | /// Gamepad top/back trigger right (second), it could be a trailing button.
67 | ///
68 | RightTrigger2,
69 |
70 | ///
71 | /// Gamepad center buttons, left one (i.e. PS3: Select).
72 | ///
73 | MiddleLeft,
74 |
75 | ///
76 | /// Gamepad center buttons, middle one (i.e. PS3: PS, Xbox: XBOX).
77 | ///
78 | Middle,
79 |
80 | ///
81 | /// Gamepad center buttons, right one (i.e. PS3: Start).
82 | ///
83 | MiddleRight,
84 |
85 | ///
86 | /// Gamepad joystick pressed button left.
87 | ///
88 | LeftThumb,
89 |
90 | ///
91 | /// Gamepad joystick pressed button right.
92 | ///
93 | RightThumb
94 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Textures/Texture2D.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Raylib_CSharp.Images;
3 | using Raylib_CSharp.Transformations;
4 | using Raylib_CSharp.Apis;
5 |
6 | namespace Raylib_CSharp.Textures;
7 |
8 | [StructLayout(LayoutKind.Sequential)]
9 | public struct Texture2D {
10 |
11 | ///
12 | /// OpenGL texture id.
13 | ///
14 | public uint Id;
15 |
16 | ///
17 | /// Texture base width.
18 | ///
19 | public int Width;
20 |
21 | ///
22 | /// Texture base height.
23 | ///
24 | public int Height;
25 |
26 | ///
27 | /// Mipmap levels, 1 by default.
28 | ///
29 | public int Mipmaps;
30 |
31 | ///
32 | /// Data format (PixelFormat type).
33 | ///
34 | public PixelFormat Format;
35 |
36 | ///
37 | public static Texture2D Load(string fileName) {
38 | return RaylibApi.LoadTexture(fileName);
39 | }
40 |
41 | ///
42 | public static Texture2D LoadFromImage(Image image) {
43 | return RaylibApi.LoadTextureFromImage(image);
44 | }
45 |
46 | ///
47 | public static Texture2D LoadCubemap(Image image, CubemapLayout layout) {
48 | return RaylibApi.LoadTextureCubemap(image, layout);
49 | }
50 |
51 | ///
52 | public bool IsValid() {
53 | return RaylibApi.IsTextureValid(this);
54 | }
55 |
56 | ///
57 | public void Unload() {
58 | RaylibApi.UnloadTexture(this);
59 | }
60 |
61 | ///
62 | public void Update(nint pixels) {
63 | RaylibApi.UpdateTexture(this, pixels);
64 | }
65 |
66 | ///
67 | public void UpdateRec(Rectangle rec, nint pixels) {
68 | RaylibApi.UpdateTextureRec(this, rec, pixels);
69 | }
70 |
71 | ///
72 | public void GenMipmaps() {
73 | RaylibApi.GenTextureMipmaps(ref this);
74 | }
75 |
76 | ///
77 | public void SetFilter(TextureFilter filter) {
78 | RaylibApi.SetTextureFilter(this, filter);
79 | }
80 |
81 | ///
82 | public void SetWrap(TextureWrap wrap) {
83 | RaylibApi.SetTextureWrap(this, wrap);
84 | }
85 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Automations/AutomationEventType.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Automations;
2 |
3 | public enum AutomationEventType {
4 |
5 | ///
6 | /// None type.
7 | ///
8 | None = 0,
9 |
10 | ///
11 | /// param[0]: key.
12 | ///
13 | KeyUp,
14 |
15 | ///
16 | /// param[0]: key.
17 | ///
18 | KeyDown,
19 |
20 | ///
21 | /// param[0]: key.
22 | ///
23 | KeyPressed,
24 |
25 | ///
26 | /// param[0]: key.
27 | ///
28 | KeyReleased,
29 |
30 | ///
31 | /// param[0]: button.
32 | ///
33 | MouseButtonUp,
34 |
35 | ///
36 | /// param[0]: button.
37 | ///
38 | MouseButtonDown,
39 |
40 | ///
41 | /// param[0]: x, param[1]: y.
42 | ///
43 | MousePosition,
44 |
45 | ///
46 | /// param[0]: x delta, param[1]: y delta.
47 | ///
48 | MouseWheelMotion,
49 |
50 | ///
51 | /// param[0]: gamepad.
52 | ///
53 | GamePadConnect,
54 |
55 | ///
56 | /// param[0]: gamepad.
57 | ///
58 | GamepadDisconnect,
59 |
60 | ///
61 | /// param[0]: button.
62 | ///
63 | GamepadButtonUp,
64 |
65 | ///
66 | /// param[0]: button.
67 | ///
68 | GamepadButtonDown,
69 |
70 | ///
71 | /// param[0]: axis, param[1]: delta.
72 | ///
73 | GamepadAxisMotion,
74 |
75 | ///
76 | /// param[0]: id.
77 | ///
78 | TouchUp,
79 |
80 | ///
81 | /// param[0]: id.
82 | ///
83 | TouchDown,
84 |
85 | ///
86 | /// param[0]: x, param[1]: y.
87 | ///
88 | TouchPosition,
89 |
90 | ///
91 | /// param[0]: gesture.
92 | ///
93 | Gesture,
94 |
95 | ///
96 | /// no params.
97 | ///
98 | WindowClose,
99 |
100 | ///
101 | /// no params.
102 | ///
103 | WindowMaximize,
104 |
105 | ///
106 | /// no params.
107 | ///
108 | WindowMinimize,
109 |
110 | ///
111 | /// param[0]: width, param[1]: height.
112 | ///
113 | WindowResize,
114 |
115 | ///
116 | /// no params.
117 | ///
118 | TakeScreenshot,
119 |
120 | ///
121 | /// param[0]: fps.
122 | ///
123 | SetTargetFps
124 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp.Samples/CMake.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | 5.5
4 |
5 |
6 |
7 | $(Configuration)/raylib.dll
8 |
9 |
10 |
11 | libraylib.so
12 |
13 |
14 |
15 | libraylib.dylib
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | %(Filename)%(Extension)
57 | PreserveNewest
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/src/Raylib-CSharp.Test/CMake.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | 5.5
4 |
5 |
6 |
7 | $(Configuration)/raylib.dll
8 |
9 |
10 |
11 | libraylib.so
12 |
13 |
14 |
15 | libraylib.dylib
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | %(Filename)%(Extension)
57 | PreserveNewest
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Shaders/Shader.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using System.Runtime.InteropServices;
3 | using Raylib_CSharp.Textures;
4 | using Raylib_CSharp.Apis;
5 |
6 | namespace Raylib_CSharp.Shaders;
7 |
8 | [StructLayout(LayoutKind.Sequential)]
9 | public struct Shader {
10 |
11 | ///
12 | /// Shader program id.
13 | ///
14 | public uint Id;
15 |
16 | ///
17 | /// Shader locations array (RL_MAX_SHADER_LOCATIONS).
18 | ///
19 | public unsafe int* LocsPtr;
20 |
21 | ///
22 | public unsafe Span Locs => new(this.LocsPtr, 32);
23 |
24 | ///
25 | public static Shader Load(string vsFileName, string fsFileName) {
26 | return RaylibApi.LoadShader(vsFileName, fsFileName);
27 | }
28 |
29 | ///
30 | public static Shader LoadFromMemory(string vsCode, string fsCode) {
31 | return RaylibApi.LoadShaderFromMemory(vsCode, fsCode);
32 | }
33 |
34 | ///
35 | public bool IsValid() {
36 | return RaylibApi.IsShaderValid(this);
37 | }
38 |
39 | ///
40 | public void Unload() {
41 | RaylibApi.UnloadShader(this);
42 | }
43 |
44 | ///
45 | public int GetLocation(string uniformName) {
46 | return RaylibApi.GetShaderLocation(this, uniformName);
47 | }
48 |
49 | ///
50 | public int GetLocationAttrib(string attribName) {
51 | return RaylibApi.GetShaderLocationAttrib(this, attribName);
52 | }
53 |
54 | ///
55 | public unsafe void SetValue(int locIndex, T value, ShaderUniformDataType uniformType) where T : unmanaged {
56 | RaylibApi.SetShaderValue(this, locIndex, &value, uniformType);
57 | }
58 |
59 | ///
60 | public unsafe void SetValueV(int locIndex, Span values, ShaderUniformDataType uniformType) where T : unmanaged {
61 | fixed (T* valuesPtr = values) {
62 | RaylibApi.SetShaderValueV(this, locIndex, valuesPtr, uniformType, values.Length);
63 | }
64 | }
65 |
66 | ///
67 | public void SetValueMatrix(int locIndex, Matrix4x4 mat) {
68 | RaylibApi.SetShaderValueMatrix(this, locIndex, mat);
69 | }
70 |
71 | ///
72 | public void SetValueTexture(int locIndex, Texture2D texture) {
73 | RaylibApi.SetShaderValueTexture(this, locIndex, texture);
74 | }
75 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Audio/Sound.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Raylib_CSharp.Apis;
3 |
4 | namespace Raylib_CSharp.Audio;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct Sound {
8 |
9 | ///
10 | /// Audio stream.
11 | ///
12 | public AudioStream Stream;
13 |
14 | ///
15 | /// Total number of frames (considering channels).
16 | ///
17 | public uint FrameCount;
18 |
19 | ///
20 | public static Sound Load(string fileName) {
21 | return RaylibApi.LoadSound(fileName);
22 | }
23 |
24 | ///
25 | public static Sound LoadFromWave(Wave wave) {
26 | return RaylibApi.LoadSoundFromWave(wave);
27 | }
28 |
29 | ///
30 | public static Sound LoadAlias(Sound source) {
31 | return RaylibApi.LoadSoundAlias(source);
32 | }
33 |
34 | ///
35 | public bool IsValid() {
36 | return RaylibApi.IsSoundValid(this);
37 | }
38 |
39 | ///
40 | public void Update(nint data, int sampleCount) {
41 | RaylibApi.UpdateSound(this, data, sampleCount);
42 | }
43 |
44 | ///
45 | public void Unload() {
46 | RaylibApi.UnloadSound(this);
47 | }
48 |
49 | ///
50 | public void UnloadAlias() {
51 | RaylibApi.UnloadSoundAlias(this);
52 | }
53 |
54 | ///
55 | public void Play() {
56 | RaylibApi.PlaySound(this);
57 | }
58 |
59 | ///
60 | public void Stop() {
61 | RaylibApi.StopSound(this);
62 | }
63 |
64 | ///
65 | public void Pause() {
66 | RaylibApi.PauseSound(this);
67 | }
68 |
69 | ///
70 | public void Resume() {
71 | RaylibApi.ResumeSound(this);
72 | }
73 |
74 | ///
75 | public bool IsPlaying() {
76 | return RaylibApi.IsSoundPlaying(this);
77 | }
78 |
79 | ///
80 | public void SetVolume(float volume) {
81 | RaylibApi.SetSoundVolume(this, volume);
82 | }
83 |
84 | ///
85 | public void SetPitch(float pitch) {
86 | RaylibApi.SetSoundPitch(this, pitch);
87 | }
88 |
89 | ///
90 | public void SetPan(float pan) {
91 | RaylibApi.SetSoundPan(this, pan);
92 | }
93 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Images/PixelFormat.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Images;
2 |
3 | public enum PixelFormat {
4 |
5 | ///
6 | /// 8 bit per pixel (no alpha).
7 | ///
8 | UncompressedGrayscale = 1,
9 |
10 | ///
11 | /// 8*2 bpp (2 channels).
12 | ///
13 | UncompressedGrayAlpha,
14 |
15 | ///
16 | /// 16 bpp.
17 | ///
18 | UncompressedR5G6B5,
19 |
20 | ///
21 | /// 24 bpp.
22 | ///
23 | UncompressedR8G8B8,
24 |
25 | ///
26 | /// 16 bpp (1 bit alpha).
27 | ///
28 | UncompressedR5G5B5A1,
29 |
30 | ///
31 | /// 16 bpp (4 bit alpha).
32 | ///
33 | UncompressedR4G4B4A4,
34 |
35 | ///
36 | /// 32 bpp.
37 | ///
38 | UncompressedR8G8B8A8,
39 |
40 | ///
41 | /// 32 bpp (1 channel - float).
42 | ///
43 | UncompressedR32,
44 |
45 | ///
46 | /// 32*3 bpp (3 channels - float).
47 | ///
48 | UncompressedR32G32B32,
49 |
50 | ///
51 | /// 32*4 bpp (4 channels - float).
52 | ///
53 | UncompressedR32G32B32A32,
54 |
55 | ///
56 | /// 16 bpp (1 channel - half float).
57 | ///
58 | UncompressedR16,
59 |
60 | ///
61 | /// 16*3 bpp (3 channels - half float).
62 | ///
63 | UncompressedR16G16B16,
64 |
65 | ///
66 | /// 16*4 bpp (4 channels - half float).
67 | ///
68 | UncompressedR16G16B16A16,
69 |
70 | ///
71 | /// 4 bpp (no alpha).
72 | ///
73 | CompressedDxt1Rgb,
74 |
75 | ///
76 | /// 4 bpp (1 bit alpha).
77 | ///
78 | CompressedDxt1Rgba,
79 |
80 | ///
81 | /// 8 bpp.
82 | ///
83 | CompressedDxt3Rgba,
84 |
85 | ///
86 | /// 8 bpp.
87 | ///
88 | CompressedDxt5Rgba,
89 |
90 | ///
91 | /// 4 bpp.
92 | ///
93 | CompressedEtc1Rgb,
94 |
95 | ///
96 | /// 4 bpp.
97 | ///
98 | CompressedEtc2Rgb,
99 |
100 | ///
101 | /// 8 bpp.
102 | ///
103 | CompressedEtc2EacRgba,
104 |
105 | ///
106 | /// 4 bpp.
107 | ///
108 | CompressedPvrtRgb,
109 |
110 | ///
111 | /// 4 bpp.
112 | ///
113 | CompressedPvrtRgba,
114 |
115 | ///
116 | /// 8 bpp.
117 | ///
118 | CompressedAstc4X4Rgba,
119 |
120 | ///
121 | /// 2 bpp.
122 | ///
123 | CompressedAstc8X8Rgba
124 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Audio/Wave.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Raylib_CSharp.Apis;
3 |
4 | namespace Raylib_CSharp.Audio;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct Wave {
8 |
9 | ///
10 | /// Total number of frames (considering channels).
11 | ///
12 | public uint FrameCount;
13 |
14 | ///
15 | /// Frequency (samples per second).
16 | ///
17 | public uint SampleRate;
18 |
19 | ///
20 | /// Bit depth (bits per sample): 8, 16, 32 (24 not supported).
21 | ///
22 | public uint SampleSize;
23 |
24 | ///
25 | /// Number of channels (1-mono, 2-stereo, ...).
26 | ///
27 | public uint Channels;
28 |
29 | ///
30 | /// Buffer data pointer.
31 | ///
32 | public nint Data;
33 |
34 | ///
35 | public static Wave Load(string fileName) {
36 | return RaylibApi.LoadWave(fileName);
37 | }
38 |
39 | ///
40 | public static unsafe Wave LoadFromMemory(string fileType, ReadOnlySpan fileData) {
41 | fixed (byte* fileDataPtr = fileData) {
42 | return RaylibApi.LoadWaveFromMemory(fileType, fileDataPtr, fileData.Length);
43 | }
44 | }
45 |
46 | ///
47 | public static unsafe void UnloadSamples(ReadOnlySpan samples) {
48 | fixed (float* samplesPtr = samples) {
49 | RaylibApi.UnloadWaveSamples(samplesPtr);
50 | }
51 | }
52 |
53 | ///
54 | public bool IsValid() {
55 | return RaylibApi.IsWaveValid(this);
56 | }
57 |
58 | ///
59 | public void Unload() {
60 | RaylibApi.UnloadWave(this);
61 | }
62 |
63 | ///
64 | public bool Export(string fileName) {
65 | return RaylibApi.ExportWave(this, fileName);
66 | }
67 |
68 | ///
69 | public bool ExportAsCode(string fileName) {
70 | return RaylibApi.ExportWaveAsCode(this, fileName);
71 | }
72 |
73 | ///
74 | public Wave Copy() {
75 | return RaylibApi.WaveCopy(this);
76 | }
77 |
78 | ///
79 | public void Crop(int initFrame, int finalFrame) {
80 | RaylibApi.WaveCrop(ref this, initFrame, finalFrame);
81 | }
82 |
83 | ///
84 | public void Format(int sampleRate, int sampleSize, int channels) {
85 | RaylibApi.WaveFormat(ref this, sampleRate, sampleSize, channels);
86 | }
87 |
88 | ///
89 | public unsafe ReadOnlySpan LoadSamples() {
90 | return new ReadOnlySpan(RaylibApi.LoadWaveSamples(this), (int)(this.FrameCount * this.Channels));
91 | }
92 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Geometry/ModelAnimation.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Raylib_CSharp.Transformations;
3 | using Raylib_CSharp.Unsafe;
4 | using Raylib_CSharp.Unsafe.Spans.Custom;
5 | using Raylib_CSharp.Apis;
6 |
7 | namespace Raylib_CSharp.Geometry;
8 |
9 | [StructLayout(LayoutKind.Sequential)]
10 | public struct ModelAnimation {
11 |
12 | ///
13 | /// Number of bones.
14 | ///
15 | public readonly int BoneCount;
16 |
17 | ///
18 | /// Number of animation frames.
19 | ///
20 | public readonly int FrameCount;
21 |
22 | ///
23 | /// Bones information (skeleton).
24 | ///
25 | public readonly unsafe BoneInfo* BonesPtr;
26 |
27 | ///
28 | public unsafe ReadOnlySpan Bones => new(this.BonesPtr, this.BoneCount);
29 |
30 | ///
31 | /// Poses array by frame.
32 | ///
33 | public readonly unsafe Transform** FramePosesPtr;
34 |
35 | ///
36 | public unsafe FixedArraySpan FramePosesCollection => new(this.FramePosesPtr, this.FrameCount, this.BoneCount);
37 |
38 | ///
39 | /// Animation name.
40 | ///
41 | public unsafe fixed sbyte NamePtr[32];
42 |
43 | ///
44 | public unsafe string Name {
45 | get {
46 | fixed (sbyte* namePtr = this.NamePtr) {
47 | return FixedString.GetValue(namePtr);
48 | }
49 | }
50 |
51 | set {
52 | fixed (sbyte* namePtr = this.NamePtr) {
53 | FixedString.SetValue(namePtr, 32, value);
54 | }
55 | }
56 | }
57 |
58 | ///
59 | public static unsafe ReadOnlySpan LoadAnimations(string fileName) {
60 | return new ReadOnlySpan(RaylibApi.LoadModelAnimations(fileName, out int animCount), animCount);
61 | }
62 |
63 | ///
64 | public static unsafe void UnloadAnimations(ReadOnlySpan animations) {
65 | fixed (ModelAnimation* animationPtr = animations) {
66 | RaylibApi.UnloadModelAnimations(animationPtr, animations.Length);
67 | }
68 | }
69 |
70 | ///
71 | public void Update(Model model, int frame) {
72 | RaylibApi.UpdateModelAnimation(model, this, frame);
73 | }
74 |
75 | ///
76 | public void UpdateBones(Model model, int frame) {
77 | RaylibApi.UpdateModelAnimationBones(model, this, frame);
78 | }
79 |
80 | ///
81 | public bool IsValid(Model model) {
82 | return RaylibApi.IsModelAnimationValid(model, this);
83 | }
84 |
85 | ///
86 | public void Unload() {
87 | RaylibApi.UnloadModelAnimation(this);
88 | }
89 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Materials/Material.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Raylib_CSharp.Colors;
3 | using Raylib_CSharp.Shaders;
4 | using Raylib_CSharp.Textures;
5 | using Raylib_CSharp.Apis;
6 |
7 | namespace Raylib_CSharp.Materials;
8 |
9 | [StructLayout(LayoutKind.Sequential)]
10 | public struct Material {
11 |
12 | ///
13 | /// Material shader.
14 | ///
15 | public Shader Shader;
16 |
17 | ///
18 | /// Material maps array (MAX_MATERIAL_MAPS).
19 | ///
20 | public unsafe MaterialMap* MapsPtr;
21 |
22 | ///
23 | public unsafe Span Maps => new(this.MapsPtr, 12);
24 |
25 | ///
26 | /// Material generic parameters (if required).
27 | ///
28 | public unsafe fixed float ParamPtr[4];
29 |
30 | ///
31 | public unsafe Span Param {
32 | get {
33 | fixed (float* paramPtr = this.ParamPtr) {
34 | return new(paramPtr, 4);
35 | }
36 | }
37 | }
38 |
39 | ///
40 | public static unsafe ReadOnlySpan LoadMaterials(string fileName) {
41 | return new ReadOnlySpan(RaylibApi.LoadMaterials(fileName, out int materialCount), materialCount);
42 | }
43 |
44 | ///
45 | public static Material LoadDefault() {
46 | return RaylibApi.LoadMaterialDefault();
47 | }
48 |
49 | ///
50 | public bool IsValid() {
51 | return RaylibApi.IsMaterialValid(this);
52 | }
53 |
54 | ///
55 | public void Unload() {
56 | RaylibApi.UnloadMaterial(this);
57 | }
58 |
59 | ///
60 | /// Set the shader for a material.
61 | ///
62 | /// The shader to set.
63 | public void SetShader(Shader shader) {
64 | this.Shader = shader;
65 | }
66 |
67 | ///
68 | /// Sets the texture for a specific material map.
69 | ///
70 | /// The index of the material map to modify.
71 | /// The texture to assign to the material map.
72 | public void SetTexture(MaterialMapIndex mapIndex, Texture2D texture) {
73 | this.Maps[(int)mapIndex].Texture = texture;
74 | }
75 |
76 | ///
77 | /// Sets the color of a specific material map.
78 | ///
79 | /// The index of the material map.
80 | /// The color to set for the material map.
81 | public void SetColor(MaterialMapIndex mapIndex, Color color) {
82 | this.Maps[(int)mapIndex].Color = color;
83 | }
84 |
85 | ///
86 | /// Sets the value of a specific map in a material.
87 | ///
88 | /// The index of the map to modify.
89 | /// The new value for the map.
90 | public void SetValue(MaterialMapIndex mapIndex, float value) {
91 | this.Maps[(int)mapIndex].Value = value;
92 | }
93 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Rendering/Gl/Contexts/LinuxGlContext.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace Raylib_CSharp.Rendering.Gl.Contexts;
5 |
6 | public partial class LinuxGlContext : IGlContext {
7 |
8 | private const string libGL = "libGL.so";
9 | private const string libGL0 = "libGL.so.0";
10 | private const string libGL1 = "libGL.so.1";
11 |
12 | private delegate nint ProcAddressDelegate(string procName);
13 |
14 | private ProcAddressDelegate[] _procAddresses;
15 |
16 | ///
17 | /// Represents a Linux binding context.
18 | ///
19 | public LinuxGlContext() {
20 | this._procAddresses = new ProcAddressDelegate[3];
21 | this._procAddresses[0] = GetXProcAddress;
22 | this._procAddresses[1] = GetXProcAddress0;
23 | this._procAddresses[2] = GetXProcAddress1;
24 | }
25 |
26 | public nint GetProcAddress(string procName) {
27 | nint address = nint.Zero;
28 |
29 | foreach (ProcAddressDelegate procAddressDelegate in this._procAddresses) {
30 | try {
31 | address = procAddressDelegate(procName);
32 |
33 | if (address != nint.Zero) {
34 | break;
35 | }
36 | }
37 | catch (Exception) {
38 | // Continue to the next delegate method
39 | }
40 | }
41 |
42 | if (address == nint.Zero) {
43 | throw new Exception("Failed to retrieve the Procedure Address.");
44 | }
45 |
46 | return address;
47 | }
48 |
49 | ///
50 | /// Retrieves the address of an OpenGL extension function.
51 | ///
52 | /// The name of the OpenGL extension function to retrieve.
53 | /// A pointer to the address of the extension function if successful; otherwise, returns NULL.
54 | [LibraryImport(libGL, EntryPoint = "glXGetProcAddress", StringMarshalling = StringMarshalling.Utf8)]
55 | [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
56 | private static partial nint GetXProcAddress(string procName);
57 |
58 | ///
59 | /// Retrieves the address of an OpenGL extension function.
60 | ///
61 | /// The name of the OpenGL extension function to retrieve.
62 | /// A pointer to the address of the extension function if successful; otherwise, returns NULL.
63 | [LibraryImport(libGL0, EntryPoint = "glXGetProcAddress", StringMarshalling = StringMarshalling.Utf8)]
64 | [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
65 | private static partial nint GetXProcAddress0(string procName);
66 |
67 | ///
68 | /// Retrieves the address of an OpenGL extension function.
69 | ///
70 | /// The name of the OpenGL extension function to retrieve.
71 | /// A pointer to the address of the extension function if successful; otherwise, returns NULL.
72 | [LibraryImport(libGL1, EntryPoint = "glXGetProcAddress", StringMarshalling = StringMarshalling.Utf8)]
73 | [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
74 | private static partial nint GetXProcAddress1(string procName);
75 | }
76 |
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Audio/Music.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Raylib_CSharp.Apis;
3 |
4 | namespace Raylib_CSharp.Audio;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct Music {
8 |
9 | ///
10 | /// Audio stream.
11 | ///
12 | public AudioStream Stream;
13 |
14 | ///
15 | /// Total number of frames (considering channels).
16 | ///
17 | public uint FrameCount;
18 |
19 | ///
20 | /// Music looping enable.
21 | ///
22 | public bool Looping;
23 |
24 | ///
25 | /// Type of music context (audio filetype).
26 | ///
27 | public int CtxType;
28 |
29 | ///
30 | /// Audio context data, depends on type.
31 | ///
32 | public nint CtxData;
33 |
34 | ///
35 | public static Music Load(string fileName) {
36 | return RaylibApi.LoadMusicStream(fileName);
37 | }
38 |
39 | ///
40 | public static unsafe Music LoadFromMemory(string fileType, ReadOnlySpan data) {
41 | fixed (byte* dataPtr = data) {
42 | return RaylibApi.LoadMusicStreamFromMemory(fileType, dataPtr, data.Length);
43 | }
44 | }
45 |
46 | ///
47 | public bool IsValid() {
48 | return RaylibApi.IsMusicValid(this);
49 | }
50 |
51 | ///
52 | public void UnloadStream() {
53 | RaylibApi.UnloadMusicStream(this);
54 | }
55 |
56 | ///
57 | public void PlayStream() {
58 | RaylibApi.PlayMusicStream(this);
59 | }
60 |
61 | ///
62 | public bool IsStreamPlaying() {
63 | return RaylibApi.IsMusicStreamPlaying(this);
64 | }
65 |
66 | ///
67 | public void UpdateStream() {
68 | RaylibApi.UpdateMusicStream(this);
69 | }
70 |
71 | ///
72 | public void StopStream() {
73 | RaylibApi.StopMusicStream(this);
74 | }
75 |
76 | ///
77 | public void PauseStream() {
78 | RaylibApi.PauseMusicStream(this);
79 | }
80 |
81 | ///
82 | public void ResumeStream() {
83 | RaylibApi.ResumeMusicStream(this);
84 | }
85 |
86 | ///
87 | public void SeekStream(float position) {
88 | RaylibApi.SeekMusicStream(this, position);
89 | }
90 |
91 | ///
92 | public void SetVolume(float volume) {
93 | RaylibApi.SetMusicVolume(this, volume);
94 | }
95 |
96 | ///
97 | public void SetPitch(float pitch) {
98 | RaylibApi.SetMusicPitch(this, pitch);
99 | }
100 |
101 | ///
102 | public void SetPan(float pan) {
103 | RaylibApi.SetMusicPan(this, pan);
104 | }
105 |
106 | ///
107 | public float GetTimeLength() {
108 | return RaylibApi.GetMusicTimeLength(this);
109 | }
110 |
111 | ///
112 | public float GetTimePlayed() {
113 | return RaylibApi.GetMusicTimePlayed(this);
114 | }
115 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Shaders/ShaderLocationIndex.cs:
--------------------------------------------------------------------------------
1 | namespace Raylib_CSharp.Shaders;
2 |
3 | public enum ShaderLocationIndex {
4 |
5 | ///
6 | /// Shader location: vertex attribute: position
7 | ///
8 | VertexPosition = 0,
9 |
10 | ///
11 | /// Shader location: vertex attribute: texcoord01
12 | ///
13 | VertexTexcoord01,
14 |
15 | ///
16 | /// Shader location: vertex attribute: texcoord02
17 | ///
18 | VertexTexcoord02,
19 |
20 | ///
21 | /// Shader location: vertex attribute: normal
22 | ///
23 | VertexNormal,
24 |
25 | ///
26 | /// Shader location: vertex attribute: tangent
27 | ///
28 | VertexTangent,
29 |
30 | ///
31 | /// Shader location: vertex attribute: color
32 | ///
33 | VertexColor,
34 |
35 | ///
36 | /// Shader location: matrix uniform: model-view-projection
37 | ///
38 | MatrixMvp,
39 |
40 | ///
41 | /// Shader location: matrix uniform: view (camera transform)
42 | ///
43 | MatrixView,
44 |
45 | ///
46 | /// Shader location: matrix uniform: projection
47 | ///
48 | MatrixProjection,
49 |
50 | ///
51 | /// Shader location: matrix uniform: model (transform)
52 | ///
53 | MatrixModel,
54 |
55 | ///
56 | /// Shader location: matrix uniform: normal
57 | ///
58 | MatrixNormal,
59 |
60 | ///
61 | /// Shader location: vector uniform: view
62 | ///
63 | VectorView,
64 |
65 | ///
66 | /// Shader location: vector uniform: diffuse color
67 | ///
68 | ColorDiffuse,
69 |
70 | ///
71 | /// Shader location: vector uniform: specular color
72 | ///
73 | ColorSpecular,
74 |
75 | ///
76 | /// Shader location: vector uniform: ambient color
77 | ///
78 | ColorAmbient,
79 |
80 | ///
81 | /// Shader location: sampler2d texture: albedo (same as: SHADER_LOC_MAP_DIFFUSE)
82 | ///
83 | MapAlbedo,
84 |
85 | ///
86 | /// Shader location: sampler2d texture: metalness (same as: SHADER_LOC_MAP_SPECULAR)
87 | ///
88 | MapMetalness,
89 |
90 | ///
91 | /// Shader location: sampler2d texture: normal
92 | ///
93 | MapNormal,
94 |
95 | ///
96 | /// Shader location: sampler2d texture: roughness
97 | ///
98 | MapRoughness,
99 |
100 | ///
101 | /// Shader location: sampler2d texture: occlusion
102 | ///
103 | MapOcclusion,
104 |
105 | ///
106 | /// Shader location: sampler2d texture: emission
107 | ///
108 | MapEmission,
109 |
110 | ///
111 | /// Shader location: sampler2d texture: height
112 | ///
113 | MapHeight,
114 |
115 | ///
116 | /// Shader location: samplerCube texture: cubemap
117 | ///
118 | MapCubemap,
119 |
120 | ///
121 | /// Shader location: samplerCube texture: irradiance
122 | ///
123 | MapIrradiance,
124 |
125 | ///
126 | /// Shader location: samplerCube texture: prefilter
127 | ///
128 | MapPrefilter,
129 |
130 | ///
131 | /// Shader location: sampler2d texture: brdf
132 | ///
133 | MapBrdf,
134 |
135 | ///
136 | /// Shader location: sampler2d texture: albedo (same as: SHADER_LOC_MAP_DIFFUSE)
137 | ///
138 | MapDiffuse = MapAlbedo,
139 |
140 | ///
141 | /// Shader location: sampler2d texture: metalness (same as: SHADER_LOC_MAP_SPECULAR)
142 | ///
143 | MapSpecular = MapMetalness
144 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp.Samples/Core/SpinningAroundADiamond.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using Raylib_CSharp.Camera.Cam3D;
3 | using Raylib_CSharp.Colors;
4 | using Raylib_CSharp.Rendering;
5 | using Raylib_CSharp.Windowing;
6 |
7 | namespace Raylib_CSharp.Samples.Core;
8 |
9 | public class SpinningAroundADiamond : ISample {
10 |
11 | public void Run() {
12 | Window.Init(800, 450, "Spinning a Diamond in 3D Space with a 3D Camera");
13 | Time.SetTargetFPS(60);
14 |
15 | // Define the camera to look into our 3D world
16 | Camera3D camera = new Camera3D {
17 | Position = new Vector3(0, 10, 70),
18 | Target = new Vector3(0, 0, 0),
19 | Up = new Vector3(0, 1, 0),
20 | FovY = 60,
21 | Projection = CameraProjection.Perspective
22 | };
23 |
24 | // Define the diamond as a series of triangles with different colors
25 | Polygon diamond = new(
26 | new Triangle(new Vector3(-25, 0, 25), new Vector3(25, 0, 25), new Vector3(0, 25, 0), Color.SkyBlue),
27 | new Triangle(new Vector3(25, 0, 25), new Vector3(25, 0, -25), new Vector3(0, 25, 0), Color.Green),
28 | new Triangle(new Vector3(25, 0, -25), new Vector3(-25, 0, -25), new Vector3(0, 25, 0), Color.Gold),
29 | new Triangle(new Vector3(-25, 0, -25), new Vector3(-25, 0, 25), new Vector3(0, 25, 0), Color.Maroon),
30 | new Triangle(new Vector3(-25, 0, 25), new Vector3(0, -25, 0), new Vector3(25, 0, 25), Color.Gold),
31 | new Triangle(new Vector3(25, 0, 25), new Vector3(0, -25, 0), new Vector3(25, 0, -25), Color.Maroon),
32 | new Triangle(new Vector3(25, 0, -25), new Vector3(0, -25, 0), new Vector3(-25, 0, -25), Color.SkyBlue),
33 | new Triangle(new Vector3(-25, 0, -25), new Vector3(0, -25, 0), new Vector3(-25, 0, 25), Color.Green)
34 | );
35 |
36 | float rotation = 0.0f;
37 | float rotationSpeedPerFrame = 0.025f;
38 |
39 | while (!Window.ShouldClose()) {
40 | Graphics.BeginDrawing();
41 | Graphics.BeginMode3D(camera);
42 | Graphics.ClearBackground(Color.LightGray);
43 |
44 | // Rotate the diamond
45 | float angle = this.CalculateRotation(rotation, rotationSpeedPerFrame);
46 | diamond.Rotate(Vector3.UnitY, angle);
47 |
48 | // Draw the diamond as a series of triangles with different colors
49 | foreach (Triangle triangle in diamond.Triangles) {
50 | triangle.Draw();
51 | }
52 |
53 | // Draw the grid on the floor to give a sense of orientation
54 | Graphics.DrawGrid(10, 100);
55 |
56 | Graphics.EndMode3D();
57 | Graphics.EndDrawing();
58 | }
59 | }
60 |
61 | private float CalculateRotation(float rotation, float rotationSpeedPerFrame) {
62 | float angle = rotation + rotationSpeedPerFrame;
63 | return angle >= 360.0f ? angle - 360.0f : angle;
64 | }
65 |
66 | private struct Polygon {
67 | public readonly Triangle[] Triangles;
68 |
69 | public Polygon(params Triangle[] triangles) {
70 | this.Triangles = triangles;
71 | }
72 |
73 | public void Rotate(Vector3 axis, float angle) {
74 | for (int index = 0; index < this.Triangles.Length; index++) {
75 | this.Triangles[index].Vertex1 = Vector3.Transform(this.Triangles[index].Vertex1, Matrix4x4.CreateFromAxisAngle(axis, angle));
76 | this.Triangles[index].Vertex2 = Vector3.Transform(this.Triangles[index].Vertex2, Matrix4x4.CreateFromAxisAngle(axis, angle));
77 | this.Triangles[index].Vertex3 = Vector3.Transform(this.Triangles[index].Vertex3, Matrix4x4.CreateFromAxisAngle(axis, angle));
78 | }
79 | }
80 | }
81 |
82 | private struct Triangle {
83 | public Vector3 Vertex1;
84 | public Vector3 Vertex2;
85 | public Vector3 Vertex3;
86 | public Color Color;
87 |
88 | public Triangle(Vector3 v1, Vector3 v2, Vector3 v3, Color color) {
89 | this.Vertex1 = v1;
90 | this.Vertex2 = v2;
91 | this.Vertex3 = v3;
92 | this.Color = color;
93 | }
94 |
95 | public void Draw() {
96 | Graphics.DrawTriangle3D(this.Vertex1, this.Vertex2, this.Vertex3, this.Color);
97 | }
98 | }
99 |
100 | ///
101 | public void Dispose() {
102 | Window.Close();
103 | }
104 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # The following command works for downloading when using Git for Windows:
2 | # curl -LOf http://gist.githubusercontent.com/kmorcinek/2710267/raw/.gitignore
3 | #
4 | # Download this file using PowerShell v3 under Windows with the following comand:
5 | # Invoke-WebRequest https://gist.githubusercontent.com/kmorcinek/2710267/raw/ -OutFile .gitignore
6 | #
7 | # or wget:
8 | # wget --no-check-certificate http://gist.githubusercontent.com/kmorcinek/2710267/raw/.gitignore
9 |
10 | # User-specific files
11 | *.suo
12 | *.user
13 | *.sln.docstates
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Rr]elease/
18 | x64/
19 | [Bb]in/
20 | [Oo]bj/
21 | # build folder is nowadays used for build scripts and should not be ignored
22 | #build/
23 |
24 | # NuGet Packages
25 | *.nupkg
26 | # The packages folder can be ignored because of Package Restore
27 | **/packages/*
28 | # except build/, which is used as an MSBuild target.
29 | !**/packages/build/
30 | # Uncomment if necessary however generally it will be regenerated when needed
31 | #!**/packages/repositories.config
32 |
33 | # MSTest test Results
34 | [Tt]est[Rr]esult*/
35 | [Bb]uild[Ll]og.*
36 |
37 | *_i.c
38 | *_p.c
39 | *.ilk
40 | *.meta
41 | *.obj
42 | *.pch
43 | *.pdb
44 | *.pgc
45 | *.pgd
46 | *.rsp
47 | *.sbr
48 | *.tlb
49 | *.tli
50 | *.tlh
51 | *.tmp
52 | *.tmp_proj
53 | *.log
54 | *.vspscc
55 | *.vssscc
56 | .builds
57 | *.pidb
58 | *.log
59 | *.scc
60 |
61 | # OS generated files #
62 | .DS_Store*
63 | Icon?
64 |
65 | # Visual C++ cache files
66 | ipch/
67 | *.aps
68 | *.ncb
69 | *.opensdf
70 | *.sdf
71 | *.cachefile
72 |
73 | # Visual Studio profiler
74 | *.psess
75 | *.vsp
76 | *.vspx
77 |
78 | # Guidance Automation Toolkit
79 | *.gpState
80 |
81 | # ReSharper is a .NET coding add-in
82 | _ReSharper*/
83 | *.[Rr]e[Ss]harper
84 |
85 | # TeamCity is a build add-in
86 | _TeamCity*
87 |
88 | # DotCover is a Code Coverage Tool
89 | *.dotCover
90 |
91 | # NCrunch
92 | *.ncrunch*
93 | .*crunch*.local.xml
94 |
95 | # Installshield output folder
96 | [Ee]xpress/
97 |
98 | # DocProject is a documentation generator add-in
99 | DocProject/buildhelp/
100 | DocProject/Help/*.HxT
101 | DocProject/Help/*.HxC
102 | DocProject/Help/*.hhc
103 | DocProject/Help/*.hhk
104 | DocProject/Help/*.hhp
105 | DocProject/Help/Html2
106 | DocProject/Help/html
107 |
108 | # Click-Once directory
109 | publish/
110 |
111 | # Publish Web Output
112 | *.Publish.xml
113 |
114 | # Windows Azure Build Output
115 | csx
116 | *.build.csdef
117 |
118 | # Windows Store app package directory
119 | AppPackages/
120 |
121 | # Others
122 | *.Cache
123 | ClientBin/
124 | [Ss]tyle[Cc]op.*
125 | ~$*
126 | *~
127 | *.dbmdl
128 | *.[Pp]ublish.xml
129 | *.pfx
130 | *.publishsettings
131 | modulesbin/
132 | tempbin/
133 |
134 | # EPiServer Site file (VPP)
135 | AppData/
136 |
137 | # RIA/Silverlight projects
138 | Generated_Code/
139 |
140 | # Backup & report files from converting an old project file to a newer
141 | # Visual Studio version. Backup files are not needed, because we have git ;-)
142 | _UpgradeReport_Files/
143 | Backup*/
144 | UpgradeLog*.XML
145 | UpgradeLog*.htm
146 |
147 | # vim
148 | *.txt~
149 | *.swp
150 | *.swo
151 |
152 | # Temp files when opening LibreOffice on ubuntu
153 | .~lock.*
154 |
155 | # svn
156 | .svn
157 |
158 | # CVS - Source Control
159 | **/CVS/
160 |
161 | # Remainings from resolving conflicts in Source Control
162 | *.orig
163 |
164 | # SQL Server files
165 | **/App_Data/*.mdf
166 | **/App_Data/*.ldf
167 | **/App_Data/*.sdf
168 |
169 |
170 | #LightSwitch generated files
171 | GeneratedArtifacts/
172 | _Pvt_Extensions/
173 | ModelManifest.xml
174 |
175 | # =========================
176 | # Windows detritus
177 | # =========================
178 |
179 | # Windows image file caches
180 | Thumbs.db
181 | ehthumbs.db
182 |
183 | # Folder config file
184 | Desktop.ini
185 |
186 | # Recycle Bin used on file shares
187 | $RECYCLE.BIN/
188 |
189 | # Mac desktop service store files
190 | .DS_Store
191 |
192 | # SASS Compiler cache
193 | .sass-cache
194 |
195 | # Visual Studio 2014 CTP
196 | **/*.sln.ide
197 |
198 | # Visual Studio temp something
199 | .vs/
200 |
201 | # dotnet stuff
202 | project.lock.json
203 |
204 | # VS 2015+
205 | *.vc.vc.opendb
206 | *.vc.db
207 |
208 | # Rider
209 | .idea/
210 |
211 | # Visual Studio Code
212 | .vscode/
213 |
214 | # Output folder used by Webpack or other FE stuff
215 | **/node_modules/*
216 | **/wwwroot/*
217 |
218 | # SpecFlow specific
219 | *.feature.cs
220 | *.feature.xlsx.*
221 | *.Specs_*.html
222 |
223 | #####
224 | # End of core ignore list, below put you custom 'per project' settings (patterns or path)
225 | #####
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Collision/ShapeHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using Raylib_CSharp.Textures;
3 | using Raylib_CSharp.Transformations;
4 | using Raylib_CSharp.Apis;
5 |
6 | namespace Raylib_CSharp.Collision;
7 |
8 | public static class ShapeHelper {
9 |
10 | ///
11 | public static void SetShapesTexture(Texture2D texture, Rectangle source) {
12 | RaylibApi.SetShapesTexture(texture, source);
13 | }
14 |
15 | ///
16 | public static Vector2 GetSplinePointLinear(Vector2 startPos, Vector2 endPos, float t) {
17 | return RaylibApi.GetSplinePointLinear(startPos, endPos, t);
18 | }
19 |
20 | ///
21 | public static Vector2 GetSplinePointBasis(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float t) {
22 | return RaylibApi.GetSplinePointBasis(p1, p2, p3, p4, t);
23 | }
24 |
25 | ///
26 | public static Vector2 GetSplinePointCatmullRom(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float t) {
27 | return RaylibApi.GetSplinePointCatmullRom(p1, p2, p3, p4, t);
28 | }
29 |
30 | ///
31 | public static Vector2 GetSplinePointBezierQuad(Vector2 p1, Vector2 c2, Vector2 p3, float t) {
32 | return RaylibApi.GetSplinePointBezierQuad(p1, c2, p3, t);
33 | }
34 |
35 | ///
36 | public static Vector2 GetSplinePointBezierCubic(Vector2 p1, Vector2 c2, Vector2 c3, Vector2 p4, float t) {
37 | return RaylibApi.GetSplinePointBezierCubic(p1, c2, c3, p4, t);
38 | }
39 |
40 | ///
41 | public static bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2) {
42 | return RaylibApi.CheckCollisionRecs(rec1, rec2);
43 | }
44 |
45 | ///
46 | public static bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2) {
47 | return RaylibApi.CheckCollisionCircles(center1, radius1, center2, radius2);
48 | }
49 |
50 | ///
51 | public static bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec) {
52 | return RaylibApi.CheckCollisionCircleRec(center, radius, rec);
53 | }
54 |
55 | ///
56 | public static bool CheckCollisionPointRec(Vector2 point, Rectangle rec) {
57 | return RaylibApi.CheckCollisionPointRec(point, rec);
58 | }
59 |
60 | ///
61 | public static bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius) {
62 | return RaylibApi.CheckCollisionPointCircle(point, center, radius);
63 | }
64 |
65 | ///
66 | public static bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3) {
67 | return RaylibApi.CheckCollisionPointTriangle(point, p1, p2, p3);
68 | }
69 |
70 | ///
71 | public static unsafe bool CheckCollisionPointPoly(Vector2 point, Span points) {
72 | fixed (Vector2* pointsPtr = points) {
73 | return RaylibApi.CheckCollisionPointPoly(point, pointsPtr, points.Length);
74 | }
75 | }
76 |
77 | ///
78 | public static bool CheckCollisionLines(Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2,
79 | ref Vector2 collisionPoint) {
80 | return RaylibApi.CheckCollisionLines(startPos1, endPos1, startPos2, endPos2, ref collisionPoint);
81 | }
82 |
83 | ///
84 | public static bool CheckCollisionPointLine(Vector2 point, Vector2 p1, Vector2 p2, int threshold) {
85 | return RaylibApi.CheckCollisionPointLine(point, p1, p2, threshold);
86 | }
87 |
88 | ///
89 | public static bool CheckCollisionCircleLine(Vector2 center, float radius, Vector2 p1, Vector2 p2) {
90 | return RaylibApi.CheckCollisionCircleLine(center, radius, p1, p2);
91 | }
92 |
93 | ///
94 | public static Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2) {
95 | return RaylibApi.GetCollisionRec(rec1, rec2);
96 | }
97 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Audio/AudioStream.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Raylib_CSharp.Apis;
3 |
4 | namespace Raylib_CSharp.Audio;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct AudioStream {
8 |
9 | ///
10 | /// Pointer to internal data used by the audio system.
11 | ///
12 | public nint Buffer;
13 |
14 | ///
15 | /// Pointer to internal data processor, useful for audio effects.
16 | ///
17 | public nint Processor;
18 |
19 | ///
20 | /// Frequency (samples per second).
21 | ///
22 | public uint SampleRate;
23 |
24 | ///
25 | /// Bit depth (bits per sample): 8, 16, 32 (24 not supported).
26 | ///
27 | public uint SampleSize;
28 |
29 | ///
30 | /// Number of channels (1-mono, 2-stereo, ...).
31 | ///
32 | public uint Channels;
33 |
34 | ///
35 | public static AudioStream Load(uint sampleRate, uint sampleSize, uint channels) {
36 | return RaylibApi.LoadAudioStream(sampleRate, sampleSize, channels);
37 | }
38 |
39 | ///
40 | public static void SetBufferSizeDefault(int size) {
41 | RaylibApi.SetAudioStreamBufferSizeDefault(size);
42 | }
43 |
44 | ///
45 | public static unsafe void SetCallback(AudioStream stream, delegate* unmanaged[Cdecl] callback) {
46 | RaylibApi.SetAudioStreamCallback(stream, callback);
47 | }
48 |
49 | ///
50 | public static unsafe void AttachProcessor(AudioStream stream, delegate* unmanaged[Cdecl] processor) {
51 | RaylibApi.AttachAudioStreamProcessor(stream, processor);
52 | }
53 |
54 | ///
55 | public static unsafe void DetachProcessor(AudioStream stream, delegate* unmanaged[Cdecl] processor) {
56 | RaylibApi.DetachAudioStreamProcessor(stream, processor);
57 | }
58 |
59 | ///
60 | public static unsafe void AttachMixedProcessor(delegate* unmanaged[Cdecl] processor) {
61 | RaylibApi.AttachAudioMixedProcessor(processor);
62 | }
63 |
64 | ///
65 | public static unsafe void DetachMixedProcessor(delegate* unmanaged[Cdecl] processor) {
66 | RaylibApi.DetachAudioMixedProcessor(processor);
67 | }
68 |
69 | ///
70 | public bool IsValid() {
71 | return RaylibApi.IsAudioStreamValid(this);
72 | }
73 |
74 | ///
75 | public void Unload() {
76 | RaylibApi.UnloadAudioStream(this);
77 | }
78 |
79 | ///
80 | public void Update(nint data, int frameCount) {
81 | RaylibApi.UpdateAudioStream(this, data, frameCount);
82 | }
83 |
84 | ///
85 | public bool IsProcessed() {
86 | return RaylibApi.IsAudioStreamProcessed(this);
87 | }
88 |
89 | ///
90 | public void Play() {
91 | RaylibApi.PlayAudioStream(this);
92 | }
93 |
94 | ///
95 | public void Pause() {
96 | RaylibApi.PauseAudioStream(this);
97 | }
98 |
99 | ///
100 | public void Resume() {
101 | RaylibApi.ResumeAudioStream(this);
102 | }
103 |
104 | ///
105 | public bool IsPlaying() {
106 | return RaylibApi.IsAudioStreamPlaying(this);
107 | }
108 |
109 | ///
110 | public void Stop() {
111 | RaylibApi.StopAudioStream(this);
112 | }
113 |
114 | ///
115 | public void SetVolume(float volume) {
116 | RaylibApi.SetAudioStreamVolume(this, volume);
117 | }
118 |
119 | ///
120 | public void SetPitch(float pitch) {
121 | RaylibApi.SetAudioStreamPitch(this, pitch);
122 | }
123 |
124 | ///
125 | public void SetPan(float pan) {
126 | RaylibApi.SetAudioStreamPan(this, pan);
127 | }
128 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Rendering/Gl/Contexts/WinGlContext.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace Raylib_CSharp.Rendering.Gl.Contexts;
5 |
6 | public partial class WinGlContext : IGlContext {
7 |
8 | private const string OpenGL32 = "opengl32";
9 | private const string Kernel32 = "kernel32";
10 |
11 | public bool HasDisposed { get; private set; }
12 |
13 | private nint _glHandle;
14 |
15 | ///
16 | /// Represents a context for managing WGL bindings.
17 | ///
18 | public WinGlContext() {
19 | this._glHandle = LoadLibrary(OpenGL32);
20 | }
21 |
22 | public nint GetProcAddress(string procName) {
23 | nint wglAddress = GetWGLProcAddress(procName);
24 |
25 | if (wglAddress == nint.Zero) {
26 | nint procAddress = GetProcAddress(this._glHandle, procName);
27 |
28 | if (procAddress == nint.Zero) {
29 | throw new Exception("Failed to retrieve the Procedure Address.");
30 | }
31 |
32 | return procAddress;
33 | }
34 |
35 | return wglAddress;
36 | }
37 |
38 | ///
39 | /// Retrieves the address of an OpenGL extension function.
40 | ///
41 | /// The name of the extension function.
42 | /// A pointer to the extension function if successful; otherwise, .
43 | [LibraryImport(OpenGL32, EntryPoint = "wglGetProcAddress", StringMarshalling = StringMarshalling.Utf8)]
44 | [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
45 | private static partial nint GetWGLProcAddress(string procName);
46 |
47 | ///
48 | /// Loads the specified dynamic-link library (DLL) into the address space of the calling process.
49 | ///
50 | /// The name of the DLL to be loaded.
51 | ///
52 | /// If the function succeeds, the return value is a handle to the loaded module.
53 | /// If the function fails, the return value is . To get extended error information, call .
54 | ///
55 | [LibraryImport(Kernel32, EntryPoint = "LoadLibraryA", SetLastError = true, StringMarshalling = StringMarshalling.Utf8)]
56 | [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
57 | private static partial nint LoadLibrary(string fileName);
58 |
59 | ///
60 | /// Retrieves the address of an exported function or variable from the specified dynamic-link library (DLL).
61 | ///
62 | /// A handle to the DLL module that contains the function or variable.
63 | /// The name of the function or variable.
64 | ///
65 | /// If the function succeeds, the return value is the address of the exported function or variable.
66 | /// If the function fails, the return value is .
67 | /// To get extended error information, call .
68 | ///
69 | [LibraryImport(Kernel32, EntryPoint = "GetProcAddress", SetLastError = true, StringMarshalling = StringMarshalling.Utf8)]
70 | [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
71 | private static partial nint GetProcAddress(nint module, string procName);
72 |
73 | ///
74 | /// Frees the loaded dynamic-link library (DLL) module.
75 | ///
76 | /// A handle to the loaded DLL module obtained from the LoadLibrary or LoadLibraryEx function.
77 | ///
78 | /// If the function succeeds, the return value is true.
79 | /// If the function fails, the return value is false.
80 | ///
81 | [LibraryImport(Kernel32, EntryPoint = "FreeLibrary", SetLastError = true)]
82 | [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
83 | [return: MarshalAs(UnmanagedType.Bool)]
84 | private static partial bool FreeLibrary(nint module);
85 |
86 | ///
87 | /// Disposes of the object, allowing for proper resource cleanup and finalization.
88 | ///
89 | public void Dispose() {
90 | if (this.HasDisposed) return;
91 |
92 | this.Dispose(true);
93 | GC.SuppressFinalize(this);
94 | this.HasDisposed = true;
95 | }
96 |
97 | ///
98 | /// Releases the managed resources used by the object (disposing), and optionally releases the unmanaged
99 | /// resources (not disposing).
100 | ///
101 | /// A boolean value indicating whether the method is being called from, dispose method directly (true) or from the finalizer (false).
102 | protected virtual void Dispose(bool disposing) {
103 | if (disposing) {
104 | FreeLibrary(this._glHandle);
105 | }
106 | }
107 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Camera/Cam3D/Camera3D.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using System.Runtime.InteropServices;
3 | using Raylib_CSharp.Collision;
4 | using Raylib_CSharp.Apis;
5 |
6 | namespace Raylib_CSharp.Camera.Cam3D;
7 |
8 | [StructLayout(LayoutKind.Sequential)]
9 | public struct Camera3D {
10 |
11 | ///
12 | /// Camera position.
13 | ///
14 | public Vector3 Position;
15 |
16 | ///
17 | /// Camera target it looks-at.
18 | ///
19 | public Vector3 Target;
20 |
21 | ///
22 | /// Camera up vector (rotation over its axis).
23 | ///
24 | public Vector3 Up;
25 |
26 | ///
27 | /// Camera field-of-view aperture in Y (degrees) in perspective, used as near plane width in orthographic.
28 | ///
29 | public float FovY;
30 |
31 | ///
32 | /// Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC.
33 | ///
34 | public CameraProjection Projection;
35 |
36 | ///
37 | /// Represents a 3D camera.
38 | ///
39 | /// Position of the camera.
40 | /// Target point of the camera.
41 | /// Up vector of the camera.
42 | /// Vertical field of view angle.
43 | /// Projection type of the camera.
44 | public Camera3D(Vector3 position, Vector3 target, Vector3 up, float fovY, CameraProjection projection) {
45 | this.Position = position;
46 | this.Target = target;
47 | this.Up = up;
48 | this.FovY = fovY;
49 | this.Projection = projection;
50 | }
51 |
52 | ///
53 | public void Update(CameraMode mode) {
54 | RaylibApi.UpdateCamera(ref this, mode);
55 | }
56 |
57 | ///
58 | public void UpdatePro(Vector3 movement, Vector3 rotation, float zoom) {
59 | RaylibApi.UpdateCameraPro(ref this, movement, rotation, zoom);
60 | }
61 |
62 | ///
63 | public Vector3 GetForward() {
64 | return RaylibApi.GetCameraForward(ref this);
65 | }
66 |
67 | ///
68 | public Vector3 GetUp() {
69 | return RaylibApi.GetCameraUp(ref this);
70 | }
71 |
72 | ///
73 | public Vector3 GetRight() {
74 | return RaylibApi.GetCameraRight(ref this);
75 | }
76 |
77 | ///
78 | public void MoveForward(float distance, bool moveInWorldPlane) {
79 | RaylibApi.CameraMoveForward(ref this, distance, moveInWorldPlane);
80 | }
81 |
82 | ///
83 | public void MoveUp(float distance) {
84 | RaylibApi.CameraMoveUp(ref this, distance);
85 | }
86 |
87 | ///
88 | public void MoveRight(float distance, bool moveInWorldPlane) {
89 | RaylibApi.CameraMoveRight(ref this, distance, moveInWorldPlane);
90 | }
91 |
92 | ///
93 | public void MoveToTarget(float delta) {
94 | RaylibApi.CameraMoveToTarget(ref this, delta);
95 | }
96 |
97 | ///
98 | public void RotateYaw(float angle, bool rotateAroundTarget) {
99 | RaylibApi.CameraYaw(ref this, angle, rotateAroundTarget);
100 | }
101 |
102 | ///
103 | public void RotatePitch(float angle, bool lockView, bool rotateAroundTarget, bool rotateUp) {
104 | RaylibApi.CameraPitch(ref this, angle, lockView, rotateAroundTarget, rotateUp);
105 | }
106 |
107 | ///
108 | public void RotateRoll(float angle) {
109 | RaylibApi.CameraRoll(ref this, angle);
110 | }
111 |
112 | ///
113 | public Matrix4x4 GetViewMatrix() {
114 | return RaylibApi.GetCameraViewMatrix(ref this);
115 | }
116 |
117 | ///
118 | public Matrix4x4 GetProjectionMatrix(float aspect) {
119 | return RaylibApi.GetCameraProjectionMatrix(ref this, aspect);
120 | }
121 |
122 | ///
123 | public Ray GetScreenToWorldRay(Vector2 position) {
124 | return RaylibApi.GetScreenToWorldRay(position, this);
125 | }
126 |
127 | ///
128 | public Ray GetScreenToWorldRayEx(Vector2 position, int width, int height) {
129 | return RaylibApi.GetScreenToWorldRayEx(position, this, width, height);
130 | }
131 |
132 | ///
133 | public Vector2 GetWorldToScreen(Vector3 position) {
134 | return RaylibApi.GetWorldToScreen(position, this);
135 | }
136 |
137 | ///
138 | public Vector2 GetWorldToScreenEx(Vector3 position, int width, int height) {
139 | return RaylibApi.GetWorldToScreenEx(position, this, width, height);
140 | }
141 |
142 | ///
143 | public Matrix4x4 GetMatrix() {
144 | return RaylibApi.GetCameraMatrix(this);
145 | }
146 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp.Test/Program.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using System.Text;
3 | using OpenTK.Graphics;
4 | using Raylib_CSharp.Camera.Cam3D;
5 | using Raylib_CSharp.Colors;
6 | using Raylib_CSharp.Fonts;
7 | using Raylib_CSharp.Geometry;
8 | using Raylib_CSharp.Images;
9 | using Raylib_CSharp.IO;
10 | using Raylib_CSharp.Logging;
11 | using Raylib_CSharp.Rendering;
12 | using Raylib_CSharp.Test;
13 | using Raylib_CSharp.Textures;
14 | using Raylib_CSharp.Unsafe.Spans.Data;
15 | using Raylib_CSharp.Windowing;
16 |
17 | Logger.Init();
18 |
19 | Logger.Message += (level, text) => {
20 | switch (level) {
21 |
22 | case TraceLogLevel.Debug:
23 | Console.ForegroundColor = ConsoleColor.Gray;
24 | Console.WriteLine(text);
25 | Console.ResetColor();
26 | return true;
27 |
28 | case TraceLogLevel.Info:
29 | Console.ForegroundColor = ConsoleColor.Cyan;
30 | Console.WriteLine(text);
31 | Console.ResetColor();
32 | return true;
33 |
34 | case TraceLogLevel.Warning:
35 | Console.ForegroundColor = ConsoleColor.Yellow;
36 | Console.WriteLine(text);
37 | Console.ResetColor();
38 | return true;
39 |
40 | case TraceLogLevel.Error:
41 | Console.ForegroundColor = ConsoleColor.Red;
42 | Console.WriteLine(text);
43 | Console.ResetColor();
44 | return true;
45 |
46 | case TraceLogLevel.Fatal:
47 | Console.ForegroundColor = ConsoleColor.Red;
48 | Console.WriteLine(text);
49 | Console.ResetColor();
50 | return true;
51 | }
52 |
53 | return false;
54 | };
55 |
56 | Window.Init(1280, 720, "Raylib-CSharp");
57 |
58 | Model model = Model.Load("content/model.glb");
59 |
60 | ReadOnlySpan animation = ModelAnimation.LoadAnimations("content/model.glb");
61 |
62 | ReadOnlySpanData data = new(animation);
63 | List> list = new();
64 | list.Add(data);
65 |
66 | //ModelAnimation.Unload(animation[0]);
67 |
68 | unsafe {
69 | Console.WriteLine(list[0].GetSpan()[0].BonesPtr[1].Name + "");
70 | }
71 |
72 | // LOAD DATA
73 | Font font = Font.Load("content/fontoe.ttf");
74 | ReadOnlySpan fileData = FileManager.LoadFileData("content/fontoe.ttf");
75 | ReadOnlySpan codepoints = TextManager.LoadCodepoints("HELLOO i like you :)");
76 | ReadOnlySpan info = Font.LoadData(fileData, 18, 95, FontType.Default);
77 |
78 | Console.WriteLine(info.Length + "");
79 |
80 | Image image = Font.GenImageAtlas(info, font.Recs, 18, 4, 0);
81 | Image clipboardImage = Window.GetClipboardImage(); //Not suported on all platforms
82 | Texture2D texture = Texture2D.LoadFromImage(image);
83 | Texture2D clipboardTexture = Texture2D.LoadFromImage(clipboardImage);
84 | image.Unload();
85 | clipboardImage.Unload();
86 |
87 |
88 | FileManager.UnloadFileData(fileData);
89 | TextManager.UnloadCodepoints(codepoints);
90 | Font.UnloadData(info);
91 |
92 | string[] testArray = new string[3];
93 | testArray[1] = "HELLOOOO";
94 | testArray[2] = "HEYYYYY";
95 |
96 | TextManager.TextJoin(testArray, "hello");
97 |
98 | Camera3D camera3D = new Camera3D() {
99 | FovY = 70,
100 | Position = new Vector3(10, 10, 10),
101 | Target = Vector3.Zero,
102 | Projection = CameraProjection.Perspective,
103 | Up = Vector3.UnitY
104 | };
105 |
106 | Color color = Color.Black;
107 | Color color1 = Color.Fade(color, 1);
108 |
109 |
110 | Font font2 = Font.GetDefault();
111 |
112 | //if (font2.IsValid()) {
113 | //
114 | //}
115 |
116 | Image testImage = Image.GenColor(100, 100, Color.Green);
117 |
118 | NativeBindingsContext context = new NativeBindingsContext();
119 | GLLoader.LoadBindings(context);
120 | Console.WriteLine($"Bones:{model.Meshes[0].BoneCount}");
121 | Console.WriteLine($"BoneMatrices:{model.Meshes[0].BoneMatrices[0]}");
122 | var dataToEncode = Encoding.ASCII.GetBytes("This is a test");
123 | Console.WriteLine($"CRC32 Checksum:{FileManager.ComputeCRC32(dataToEncode)}"); //As ISO-HDLC
124 |
125 | uint[] md5Hash = FileManager.ComputeMD5(dataToEncode);
126 | string hexString = string.Join("", md5Hash.Select(x => x.ToString("x8")));
127 | Console.WriteLine($"MD5 Checksum: {hexString}");
128 |
129 | uint[] sha1Hash = FileManager.ComputeSHA1(dataToEncode);
130 | hexString = string.Join("", sha1Hash.Select(x => x.ToString("x8")));
131 | Console.WriteLine($"SHA1 Checksum: {hexString}");
132 |
133 | //Span matrix = new(new Matrix4x4[1]);
134 | //matrix[1] = new Matrix4x4();
135 |
136 | while (!Window.ShouldClose()) {
137 | camera3D.Update(CameraMode.Orbital);
138 |
139 | Graphics.BeginDrawing();
140 | Graphics.ClearBackground(Color.SkyBlue);
141 |
142 | //GL.UseProgram((int) RlGl.GetShaderIdDefault());
143 |
144 | //Console.WriteLine(GladApi.GetString(0x1F02) + "");
145 |
146 | Graphics.BeginMode3D(camera3D);
147 | Graphics.DrawGrid(100, 1);
148 | Graphics.DrawModel(model, Vector3.UnitY / 2, 1, Color.Alpha(Color.Green, 0.5F));
149 | Graphics.EndMode3D();
150 |
151 | Graphics.DrawFPS(50, 50);
152 | Graphics.DrawTexture(texture, 10, 10, Color.White);
153 | Graphics.DrawTexture(clipboardTexture, 128, 128, Color.White);
154 |
155 | Graphics.EndDrawing();
156 | }
157 |
158 | FilePathList test = FileManager.LoadDirectoryFiles("content");
159 | Logger.TraceLog(TraceLogLevel.Error, "Path: " + test.Paths[0]);
160 |
161 | model.Materials[0].Unload();
162 | model.MaterialCount = 0;
163 |
164 | model.Unload();
165 |
166 | Window.Close();
167 | context.Dispose();
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Fonts/Font.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Raylib_CSharp.Apis;
3 | using Raylib_CSharp.Colors;
4 | using Raylib_CSharp.Images;
5 | using Raylib_CSharp.Textures;
6 | using Raylib_CSharp.Transformations;
7 |
8 | namespace Raylib_CSharp.Fonts;
9 |
10 | [StructLayout(LayoutKind.Sequential)]
11 | public struct Font {
12 |
13 | ///
14 | /// Base size (default chars height).
15 | ///
16 | public int BaseSize;
17 |
18 | ///
19 | /// Number of glyph characters.
20 | ///
21 | public int GlyphCount;
22 |
23 | ///
24 | /// Padding around the glyph characters.
25 | ///
26 | public int GlyphPadding;
27 |
28 | ///
29 | /// Texture atlas containing the glyphs.
30 | ///
31 | public Texture2D Texture;
32 |
33 | ///
34 | /// Rectangles in texture for the glyphs.
35 | ///
36 | public unsafe Rectangle* RecsPtr;
37 |
38 | ///
39 | public unsafe Span Recs => new(this.RecsPtr, this.GlyphCount);
40 |
41 | ///
42 | /// Glyphs info data.
43 | ///
44 | public unsafe GlyphInfo* GlyphsPtr;
45 |
46 | ///
47 | public unsafe Span Glyphs => new(this.GlyphsPtr, this.GlyphCount);
48 |
49 | ///
50 | public static Font GetDefault() {
51 | return RaylibApi.GetFontDefault();
52 | }
53 |
54 | ///
55 | public static Font Load(string fileName) {
56 | return RaylibApi.LoadFont(fileName);
57 | }
58 |
59 | ///
60 | public static unsafe Font LoadEx(string fileName, int fontSize, ReadOnlySpan codepoints) {
61 | fixed (int* codepointsPtr = codepoints) {
62 | return RaylibApi.LoadFontEx(fileName, fontSize, codepointsPtr, codepoints.Length);
63 | }
64 | }
65 |
66 | ///
67 | public static Font LoadFromImage(Image image, Color key, int firstChar) {
68 | return RaylibApi.LoadFontFromImage(image, key, firstChar);
69 | }
70 |
71 | ///
72 | public static unsafe Font LoadFromMemory(string fileType, ReadOnlySpan fileData, int fontSize, ReadOnlySpan codepoints) {
73 | fixed (byte* fileDataPtr = fileData) {
74 | fixed (int* codepointsPtr = codepoints) {
75 | return RaylibApi.LoadFontFromMemory(fileType, fileDataPtr, fileData.Length, fontSize, codepointsPtr, codepoints.Length);
76 | }
77 | }
78 | }
79 |
80 | ///
81 | public static unsafe ReadOnlySpan LoadData(ReadOnlySpan fileData, int fontSize, ReadOnlySpan codepoints, FontType type) {
82 | fixed (byte* fileDataPtr = fileData) {
83 | fixed (int* codepointsPtr = codepoints) {
84 | return new ReadOnlySpan(RaylibApi.LoadFontData(fileDataPtr, fileData.Length, fontSize, codepointsPtr, codepoints.Length, type), codepoints.Length);
85 | }
86 | }
87 | }
88 |
89 | ///
90 | public static unsafe ReadOnlySpan LoadData(ReadOnlySpan fileData, int fontSize, int codepointCount, FontType type) {
91 | fixed (byte* fileDataPtr = fileData) {
92 | return new ReadOnlySpan(RaylibApi.LoadFontData(fileDataPtr, fileData.Length, fontSize, null, codepointCount, type), codepointCount);
93 | }
94 | }
95 |
96 | ///
97 | public static unsafe Image GenImageAtlas(ReadOnlySpan glyphs, ReadOnlySpan glyphRecs, int fontSize, int padding, int packMethod) {
98 | fixed (GlyphInfo* glyphsPtr = glyphs) {
99 | fixed (Rectangle* glyphRecsPtr = glyphRecs) {
100 | return RaylibApi.GenImageFontAtlas(glyphsPtr, &glyphRecsPtr, glyphs.Length, fontSize, padding, packMethod);
101 | }
102 | }
103 | }
104 |
105 | ///
106 | public static unsafe void UnloadData(ReadOnlySpan glyphs) {
107 | fixed (GlyphInfo* glyphsPtr = glyphs) {
108 | RaylibApi.UnloadFontData(glyphsPtr, glyphs.Length);
109 | }
110 | }
111 |
112 | ///
113 | public bool IsValid() {
114 | return RaylibApi.IsFontValid(this);
115 | }
116 |
117 | ///
118 | public void Unload() {
119 | RaylibApi.UnloadFont(this);
120 | }
121 |
122 | ///
123 | public bool ExportAsCode(string fileName) {
124 | return RaylibApi.ExportFontAsCode(this, fileName);
125 | }
126 |
127 | ///
128 | public int GetGlyphIndex(int codepoint) {
129 | return RaylibApi.GetGlyphIndex(this, codepoint);
130 | }
131 |
132 | ///
133 | public GlyphInfo GetGlyphInfo(int codepoint) {
134 | return RaylibApi.GetGlyphInfo(this, codepoint);
135 | }
136 |
137 | ///
138 | public Rectangle GetGlyphAtlasRec(int codepoint) {
139 | return RaylibApi.GetGlyphAtlasRec(this, codepoint);
140 | }
141 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | # Raylib-CSharp 🚀
6 | [](https://discord.gg/7XKw6YQa76)
7 | [](LICENSE)
8 | [](https://github.com/MrScautHD/Raylib-CSharp/activity)
9 | [](https://github.com/MrScautHD/Raylib-CSharp/stargazers)
10 |
11 | __Raylib-CSharp__ is a fully managed binding over `Raylib-5.5`.
12 |
13 | ---
14 |
15 | # 🔧 **Advanced Renderer** 🚀
16 | Discover the powerful features of our **✨new✨ Render Framework, [Bliss](https://github.com/MrScautHD/Bliss)**.
17 |
18 |
19 |
20 |
21 |
22 | Bliss is a **modern rendering solution** supporting:
23 | - 🎮 **Direct3D11**
24 | - 🌋 **Vulkan**
25 | - 🖼️ **OpenGL**
26 | - 🍎 **Metal**
27 | - 📱 **OpenGL-ES**
28 |
29 | Unlock advanced rendering capabilities with [Bliss](https://github.com/MrScautHD/Bliss) today!
30 |
31 | # 🪙 Installation - [Nuget](https://www.nuget.org/packages/Raylib-CSharp)
32 | ```
33 | dotnet add package Raylib-CSharp --version 5.0.0
34 | ```
35 |
36 | # 📖 [Installation - From source]
37 | > 1. Clone this repository.
38 | > 2. Add `Raylib-CSharp.csproj` as a reference to your project.
39 | > 3. Ensure that you integrate the [`CMake.props`](https://github.com/MrScautHD/Raylib-CSharp/blob/main/src/Raylib-CSharp.Test/CMake.props) file into your project setup to facilitate the building process for the .dlls.
40 | ---
41 |
42 | # 💻 Platforms
43 | [
](https://www.microsoft.com/de-at/windows)
44 | ### Windows
45 | - Graphics APIs: `OpenGL-4.3`
46 |
47 | [
](https://www.ubuntu.com/)
48 | ### Linux
49 | - Graphics APIs: `OpenGL-4.3`
50 |
51 | [
](https://www.apple.com/at/macos/sonoma/)
52 | ### MacOS
53 | - Graphics APIs: `OpenGL-3.3`
54 |
55 | # 🧑 Contributors
56 |
57 |
58 |
59 |
60 | # ✉️ Reach us
61 | [
](https://discord.gg/7XKw6YQa76)
62 | [
](https://github.com/sponsors/MrScautHD)
63 |
64 | ---
65 |
66 | # 📖 Differences from [`Raylib-cs`](https://github.com/ChrisDill/Raylib-cs)
67 |
68 | | Raylib-cs | `Raylib-CSharp` |
69 | | -------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
70 | | One Binding Class (`Raylib.cs`). | Managed Classes like `Window, Music...`. |
71 | | Uses `DllImport` and makes using pointers `required` in some cases. | Uses `LibraryImport` and using pointers is `optional`. |
72 | | Using one `Namespace`. | Using multiple `Namespaces`! |
73 | | .NET 5.0, 6.0 / C# 10 | .NET 8.0 / C# 12 |
74 | | Released 2018-07 | Released 2024-05 |
75 | | License ZLib | License MIT |
76 | | Raylib 5.0 | Raylib 5.5 |
77 |
78 | # ✍️ Acknowledgement
79 | This library is available under the [MIT](https://choosealicense.com/licenses/mit) license.
80 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 | We as members, contributors, and leaders pledge to make participation in our
5 | community a harassment-free experience for everyone, regardless of age, body
6 | size, visible or invisible disability, ethnicity, sex characteristics, gender
7 | identity and expression, level of experience, education, socio-economic status,
8 | nationality, personal appearance, race, caste, color, religion, or sexual
9 | identity and orientation.
10 |
11 | We pledge to act and interact in ways that contribute to an open, welcoming,
12 | diverse, inclusive, and healthy community.
13 |
14 | ## Our Standards
15 | Examples of behavior that contributes to a positive environment for our
16 | community include:
17 |
18 | * Demonstrating empathy and kindness toward other people
19 | * Being respectful of differing opinions, viewpoints, and experiences
20 | * Giving and gracefully accepting constructive feedback
21 | * Accepting responsibility and apologizing to those affected by our mistakes,
22 | and learning from the experience
23 | * Focusing on what is best not just for us as individuals, but for the overall
24 | community
25 |
26 | Examples of unacceptable behavior include:
27 |
28 | * The use of sexualized language or imagery, and sexual attention or advances of
29 | any kind
30 | * Trolling, insulting or derogatory comments, and personal or political attacks
31 | * Public or private harassment
32 | * Publishing others' private information, such as a physical or email address,
33 | without their explicit permission
34 | * Other conduct which could reasonably be considered inappropriate in a
35 | professional setting
36 |
37 | ## Enforcement Responsibilities
38 | Community leaders are responsible for clarifying and enforcing our standards of
39 | acceptable behavior and will take appropriate and fair corrective action in
40 | response to any behavior that they deem inappropriate, threatening, offensive,
41 | or harmful.
42 |
43 | Community leaders have the right and responsibility to remove, edit, or reject
44 | comments, commits, code, wiki edits, issues, and other contributions that are
45 | not aligned to this Code of Conduct, and will communicate reasons for moderation
46 | decisions when appropriate.
47 |
48 | ## Scope
49 | This Code of Conduct applies within all community spaces, and also applies when
50 | an individual is officially representing the community in public spaces.
51 | Examples of representing our community include using an official email address,
52 | posting via an official social media account, or acting as an appointed
53 | representative at an online or offline event.
54 |
55 | ## Enforcement
56 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
57 | reported to the community leaders responsible for enforcement at
58 | [INSERT CONTACT METHOD].
59 | All complaints will be reviewed and investigated promptly and fairly.
60 |
61 | All community leaders are obligated to respect the privacy and security of the
62 | reporter of any incident.
63 |
64 | ## Enforcement Guidelines
65 | Community leaders will follow these Community Impact Guidelines in determining
66 | the consequences for any action they deem in violation of this Code of Conduct:
67 |
68 | ### 1. Correction
69 | **Community Impact**: Use of inappropriate language or other behavior deemed
70 | unprofessional or unwelcome in the community.
71 |
72 | **Consequence**: A private, written warning from community leaders, providing
73 | clarity around the nature of the violation and an explanation of why the
74 | behavior was inappropriate. A public apology may be requested.
75 |
76 | ### 2. Warning
77 | **Community Impact**: A violation through a single incident or series of
78 | actions.
79 |
80 | **Consequence**: A warning with consequences for continued behavior. No
81 | interaction with the people involved, including unsolicited interaction with
82 | those enforcing the Code of Conduct, for a specified period of time. This
83 | includes avoiding interactions in community spaces as well as external channels
84 | like social media. Violating these terms may lead to a temporary or permanent
85 | ban.
86 |
87 | ### 3. Temporary Ban
88 | **Community Impact**: A serious violation of community standards, including
89 | sustained inappropriate behavior.
90 |
91 | **Consequence**: A temporary ban from any sort of interaction or public
92 | communication with the community for a specified period of time. No public or
93 | private interaction with the people involved, including unsolicited interaction
94 | with those enforcing the Code of Conduct, is allowed during this period.
95 | Violating these terms may lead to a permanent ban.
96 |
97 | ### 4. Permanent Ban
98 | **Community Impact**: Demonstrating a pattern of violation of community
99 | standards, including sustained inappropriate behavior, harassment of an
100 | individual, or aggression toward or disparagement of classes of individuals.
101 |
102 | **Consequence**: A permanent ban from any sort of public interaction within the
103 | community.
104 |
105 | ## Attribution
106 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
107 | version 2.1, available at
108 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
109 |
110 | Community Impact Guidelines were inspired by
111 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
112 |
113 | For answers to common questions about this code of conduct, see the FAQ at
114 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
115 | [https://www.contributor-covenant.org/translations][translations].
116 |
117 | [homepage]: https://www.contributor-covenant.org
118 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
119 | [Mozilla CoC]: https://github.com/mozilla/diversity
120 | [FAQ]: https://www.contributor-covenant.org/faq
121 | [translations]: https://www.contributor-covenant.org/translations
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Fonts/TextManager.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using Raylib_CSharp.Apis;
3 |
4 | namespace Raylib_CSharp.Fonts;
5 |
6 | public static class TextManager {
7 |
8 | ///
9 | public static unsafe string LoadUTF8(ReadOnlySpan codepoints) {
10 | fixed (int* codepointsPtr = codepoints) {
11 | return RaylibApi.LoadUTF8(codepointsPtr, codepoints.Length);
12 | }
13 | }
14 |
15 | ///
16 | public static void UnloadUTF8(string text) {
17 | RaylibApi.UnloadUTF8(text);
18 | }
19 |
20 | ///
21 | public static unsafe ReadOnlySpan LoadCodepoints(string text) {
22 | return new ReadOnlySpan(RaylibApi.LoadCodepoints(text, out int count), count);
23 | }
24 |
25 | ///
26 | public static unsafe void UnloadCodepoints(ReadOnlySpan codepoints) {
27 | fixed (int* codepointsPtr = codepoints) {
28 | RaylibApi.UnloadCodepoints(codepointsPtr);
29 | }
30 | }
31 |
32 | ///
33 | public static int GetCodepointCount(string text) {
34 | return RaylibApi.GetCodepointCount(text);
35 | }
36 |
37 | ///
38 | public static int GetCodepoint(string text, out int codepointSize) {
39 | return RaylibApi.GetCodepoint(text, out codepointSize);
40 | }
41 |
42 | ///
43 | public static int GetCodepointNext(string text, out int codepointSize) {
44 | return RaylibApi.GetCodepointNext(text, out codepointSize);
45 | }
46 |
47 | ///
48 | public static int GetCodepointPrevious(string text, out int codepointSize) {
49 | return RaylibApi.GetCodepointPrevious(text, out codepointSize);
50 | }
51 |
52 | ///
53 | public static string CodepointToUTF8(int codepoint, out int utf8Size) {
54 | return RaylibApi.CodepointToUTF8(codepoint, out utf8Size);
55 | }
56 |
57 | ///
58 | public static void SetTextLineSpacing(int spacing) {
59 | RaylibApi.SetTextLineSpacing(spacing);
60 | }
61 |
62 | ///
63 | public static int MeasureText(string text, int fontSize) {
64 | return RaylibApi.MeasureText(text, fontSize);
65 | }
66 |
67 | ///
68 | public static Vector2 MeasureTextEx(Font font, string text, float fontSize, float spacing) {
69 | return RaylibApi.MeasureTextEx(font, text, fontSize, spacing);
70 | }
71 |
72 | ///
73 | public static int TextCopy(string dst, string src) {
74 | return RaylibApi.TextCopy(dst, src);
75 | }
76 |
77 | ///
78 | public static bool TextIsEqual(string text1, string text2) {
79 | return RaylibApi.TextIsEqual(text1, text2);
80 | }
81 |
82 | ///
83 | public static uint TextLength(string text) {
84 | return RaylibApi.TextLength(text);
85 | }
86 |
87 | ///
88 | public static string TextFormat(string text) {
89 | return RaylibApi.TextFormat(text);
90 | }
91 |
92 | ///
93 | public static string TextSubtext(string text, int position, int length) {
94 | return RaylibApi.TextSubtext(text, position, length);
95 | }
96 |
97 | ///
98 | public static string TextReplace(string text, string replace, string by) {
99 | return RaylibApi.TextReplace(text, replace, by);
100 | }
101 |
102 | ///
103 | public static string TextInsert(string text, string insert, int position) {
104 | return RaylibApi.TextInsert(text, insert, position);
105 | }
106 |
107 | ///
108 | public static string TextJoin(string[] textList, string delimiter) {
109 | return string.Join(delimiter, textList);
110 | }
111 |
112 | ///
113 | public static string[] TextSplit(string text, string delimiter) {
114 | return text.Split(delimiter);
115 | }
116 |
117 | ///
118 | public static void TextAppend(string text, string append, out int position) {
119 | RaylibApi.TextAppend(text, append, out position);
120 | }
121 |
122 | ///
123 | public static int TextFindIndex(string text, string find) {
124 | return RaylibApi.TextFindIndex(text, find);
125 | }
126 |
127 | ///
128 | public static string TextToUpper(string text) {
129 | return RaylibApi.TextToUpper(text);
130 | }
131 |
132 | ///
133 | public static string TextToLower(string text) {
134 | return RaylibApi.TextToLower(text);
135 | }
136 |
137 | ///
138 | public static string TextToPascal(string text) {
139 | return RaylibApi.TextToPascal(text);
140 | }
141 |
142 | ///
143 | public static string TextToSnake(string text) {
144 | return RaylibApi.TextToSnake(text);
145 | }
146 |
147 | ///
148 | public static string TextToCamel(string text) {
149 | return RaylibApi.TextToCamel(text);
150 | }
151 |
152 | ///
153 | public static int TextToInteger(string text) {
154 | return RaylibApi.TextToInteger(text);
155 | }
156 |
157 | ///
158 | public static float TextToFloat(string text) {
159 | return RaylibApi.TextToFloat(text);
160 | }
161 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Colors/Color.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using System.Runtime.InteropServices;
3 | using Raylib_CSharp.Images;
4 | using Raylib_CSharp.Apis;
5 |
6 | namespace Raylib_CSharp.Colors;
7 |
8 | [StructLayout(LayoutKind.Sequential)]
9 | public struct Color {
10 |
11 | public static readonly Color LightGray = new(200, 200, 200, 255);
12 | public static readonly Color Gray = new(130, 130, 130, 255);
13 | public static readonly Color DarkGray = new(80, 80, 80, 255);
14 | public static readonly Color Yellow = new(253, 249, 0, 255);
15 | public static readonly Color Gold = new(255, 203, 0, 255);
16 | public static readonly Color Orange = new(255, 161, 0, 255);
17 | public static readonly Color Pink = new(255, 109, 194, 255);
18 | public static readonly Color Red = new(230, 41, 55, 255);
19 | public static readonly Color Maroon = new(190, 33, 55, 255);
20 | public static readonly Color Green = new(0, 228, 48, 255);
21 | public static readonly Color Lime = new(0, 158, 47, 255);
22 | public static readonly Color DarkGreen = new(0, 117, 44, 255);
23 | public static readonly Color SkyBlue = new(102, 191, 255, 255);
24 | public static readonly Color Blue = new(0, 121, 241, 255);
25 | public static readonly Color DarkBlue = new(0, 82, 172, 255);
26 | public static readonly Color Purple = new(200, 122, 255, 255);
27 | public static readonly Color Violet = new(135, 60, 190, 255);
28 | public static readonly Color DarkPurple = new(112, 31, 126, 255);
29 | public static readonly Color Beige = new(211, 176, 131, 255);
30 | public static readonly Color Brown = new(127, 106, 79, 255);
31 | public static readonly Color DarkBrown = new(76, 63, 47, 255);
32 | public static readonly Color White = new(255, 255, 255, 255);
33 | public static readonly Color Black = new(0, 0, 0, 255);
34 | public static readonly Color Blank = new(0, 0, 0, 0);
35 | public static readonly Color Magenta = new(255, 0, 255, 255);
36 | public static readonly Color RayWhite = new(245, 245, 245, 255);
37 |
38 | ///
39 | /// Color red value.
40 | ///
41 | public byte R;
42 |
43 | ///
44 | /// Color green value.
45 | ///
46 | public byte G;
47 |
48 | ///
49 | /// Color blue value.
50 | ///
51 | public byte B;
52 |
53 | ///
54 | /// Color alpha value.
55 | ///
56 | public byte A;
57 |
58 | ///
59 | /// Color, 4 components, R8G8B8A8 (32bit).
60 | ///
61 | /// Red component value.
62 | /// Green component value.
63 | /// Blue component value.
64 | /// Alpha component value.
65 | public Color(byte r, byte g, byte b, byte a) {
66 | this.R = r;
67 | this.G = g;
68 | this.B = b;
69 | this.A = a;
70 | }
71 |
72 | public override string ToString() {
73 | return $"R:{this.R} G:{this.G} B:{this.B} A:{this.A}";
74 | }
75 |
76 | ///
77 | public static bool IsEqual(Color col1, Color col2) {
78 | return RaylibApi.ColorIsEqual(col1, col2);
79 | }
80 |
81 | ///
82 | public static Color Fade(Color color, float alpha) {
83 | return RaylibApi.Fade(color, alpha);
84 | }
85 |
86 | ///
87 | public static int ToInt(Color color) {
88 | return RaylibApi.ColorToInt(color);
89 | }
90 |
91 | ///
92 | public static Vector4 Normalize(Color color) {
93 | return RaylibApi.ColorNormalize(color);
94 | }
95 |
96 | ///
97 | public static Color FromNormalized(Vector4 normalized) {
98 | return RaylibApi.ColorFromNormalized(normalized);
99 | }
100 |
101 | ///
102 | public static Vector3 ToHSV(Color color) {
103 | return RaylibApi.ColorToHSV(color);
104 | }
105 |
106 | ///
107 | public static Color FromHSV(float hue, float saturation, float value) {
108 | return RaylibApi.ColorFromHSV(hue, saturation, value);
109 | }
110 |
111 | ///
112 | public static Color Tint(Color color, Color tint) {
113 | return RaylibApi.ColorTint(color, tint);
114 | }
115 |
116 | ///
117 | public static Color Brightness(Color color, float factor) {
118 | return RaylibApi.ColorBrightness(color, factor);
119 | }
120 |
121 | ///
122 | public static Color Contrast(Color color, float contrast) {
123 | return RaylibApi.ColorContrast(color, contrast);
124 | }
125 |
126 | ///
127 | public static Color Alpha(Color color, float alpha) {
128 | return RaylibApi.ColorAlpha(color, alpha);
129 | }
130 |
131 | ///
132 | public static Color AlphaBlend(Color dst, Color src, Color tint) {
133 | return RaylibApi.ColorAlphaBlend(dst, src, tint);
134 | }
135 |
136 | ///
137 | public static Color Lerp(Color color1, Color color2, float factor) {
138 | return RaylibApi.ColorLerp(color1, color2, factor);
139 | }
140 |
141 | ///
142 | public static Color FromHex(uint hexValue) {
143 | return RaylibApi.GetColor(hexValue);
144 | }
145 |
146 | ///
147 | public static Color GetPixelColor(nint srcPtr, PixelFormat format) {
148 | return RaylibApi.GetPixelColor(srcPtr, format);
149 | }
150 |
151 | ///
152 | public static void SetPixelColor(nint dstPtr, Color color, PixelFormat format) {
153 | RaylibApi.SetPixelColor(dstPtr, color, format);
154 | }
155 |
156 | ///
157 | public static int GetPixelDataSize(int width, int height, PixelFormat format) {
158 | return RaylibApi.GetPixelDataSize(width, height, format);
159 | }
160 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp.Samples/Core/Pong.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using Raylib_CSharp.Colors;
3 | using Raylib_CSharp.Interact;
4 | using Raylib_CSharp.Logging;
5 | using Raylib_CSharp.Rendering;
6 | using Raylib_CSharp.Transformations;
7 | using Raylib_CSharp.Windowing;
8 |
9 | namespace Raylib_CSharp.Samples.Core;
10 |
11 | public class Pong : ISample {
12 |
13 | private const int _screenWidth = 1280;
14 | private const int _screenHeight = 720;
15 |
16 | private const float _ballRadius = 10;
17 | private const float _ballBaseSpeed = 7.0f;
18 | private const float _paddleSpeed = 7.0f;
19 |
20 | private readonly Vector2 _center = new(_screenWidth / 2.0F, _screenHeight / 2.0F);
21 |
22 | private readonly Tuple _leftSide = new Tuple(new Vector2(0, 0), new Vector2(0, _screenHeight));
23 | private readonly Tuple _rightSide = new Tuple(new Vector2(_screenWidth, 0), new Vector2(_screenWidth, _screenHeight));
24 |
25 | private Rectangle _leftPaddle = new Rectangle(50, _screenHeight / 2.0F - 60, 20, 120);
26 | private Rectangle _rightPaddle = new Rectangle(_screenWidth - 70, _screenHeight / 2.0F - 60, 20, 120);
27 |
28 | private Vector2 _ballPosition = new Vector2(_screenWidth / 2.0F, _screenHeight / 2.0F);
29 | private Vector2 _ballSpeed = new Vector2(_ballBaseSpeed, _ballBaseSpeed);
30 |
31 | private int _leftPaddleScore;
32 | private int _rightPaddleScore;
33 |
34 | public void Run() {
35 | Window.Init(_screenWidth, _screenHeight, "Pong");
36 |
37 | Logger.SetTraceLogLevel(TraceLogLevel.Warning);
38 | Time.SetTargetFPS(60);
39 |
40 | while (!Window.ShouldClose()) {
41 | this.DrawFrame();
42 | }
43 | }
44 |
45 | ///
46 | /// Draws the game frame on the screen.
47 | ///
48 | private void DrawFrame() {
49 | Graphics.BeginDrawing();
50 | Graphics.ClearBackground(Color.Black);
51 |
52 | // Draw game title and scores
53 | Graphics.DrawText("Pong!", 10, 10, 20, Color.White);
54 | Graphics.DrawText(this._leftPaddleScore.ToString(), _screenWidth / 2 - 50, 10, 20, Color.White);
55 | Graphics.DrawText(this._rightPaddleScore.ToString(), _screenWidth / 2 + 30, 10, 20, Color.White);
56 |
57 | // Handle input for left paddle
58 | if (Input.IsKeyDown(KeyboardKey.W) && this._leftPaddle.Y > 0) this._leftPaddle.Y -= _paddleSpeed;
59 | if (Input.IsKeyDown(KeyboardKey.S) && this._leftPaddle.Y < _screenHeight - this._leftPaddle.Height) this._leftPaddle.Y += _paddleSpeed;
60 |
61 | // Handle input for right paddle
62 | if (Input.IsKeyDown(KeyboardKey.Up) && this._rightPaddle.Y > 0) this._rightPaddle.Y -= _paddleSpeed;
63 | if (Input.IsKeyDown(KeyboardKey.Down) && this._rightPaddle.Y < _screenHeight - this._rightPaddle.Height) this._rightPaddle.Y += _paddleSpeed;
64 |
65 | // Ball movement
66 | this._ballPosition += this._ballSpeed;
67 |
68 | // Ball collision with top and bottom
69 | if (this._ballPosition.Y <= _ballRadius || this._ballPosition.Y >= _screenHeight - _ballRadius) this._ballSpeed.Y *= -1;
70 |
71 | // Ball collision with paddles
72 | if (Collision.ShapeHelper.CheckCollisionCircleRec(this._ballPosition, _ballRadius, this._leftPaddle) ||
73 | Collision.ShapeHelper.CheckCollisionCircleRec(this._ballPosition, _ballRadius, this._rightPaddle))
74 | this._ballSpeed.X *= -1;
75 |
76 | // Ball goes out of bounds, reset position, increase speed, and update score
77 | if (this._ballPosition.X is < 0 or > _screenWidth) {
78 | Side winningSide = this._ballPosition.X < 0 ? Side.Left : Side.Right;
79 |
80 | if (winningSide == Side.Left)
81 | this._rightPaddleScore++;
82 | else
83 | this._leftPaddleScore++;
84 |
85 | // Update ball position to center
86 | this._ballPosition = this._center;
87 |
88 | // Increase ball speed based on scores
89 | float speedIncreaseFactor = 1 + (this._leftPaddleScore + this._rightPaddleScore) * 0.1f;
90 | Vector2 target = this.GetRandomTargetForDirection(winningSide);
91 | Vector2 ballDirection = GetDirectionToTarget(this._center, target);
92 | this._ballSpeed = new Vector2(ballDirection.X * _ballBaseSpeed * speedIncreaseFactor, ballDirection.Y * _ballBaseSpeed * speedIncreaseFactor);
93 | }
94 |
95 | // Draw ball
96 | Graphics.DrawCircleV(this._ballPosition, _ballRadius, Color.White);
97 |
98 | // Draw paddles
99 | Graphics.DrawRectangleRec(this._leftPaddle, Color.White);
100 | Graphics.DrawRectangleRec(this._rightPaddle, Color.White);
101 |
102 | Graphics.EndDrawing();
103 | }
104 |
105 | ///
106 | /// Calculates the normalized direction vector from origin to target.
107 | ///
108 | /// The origin position.
109 | /// The target position.
110 | /// The normalized direction vector from origin to target.
111 | private static Vector2 GetDirectionToTarget(Vector2 origin, Vector2 target) {
112 | Vector2 direction = target - origin;
113 | return Vector2.Normalize(direction);
114 | }
115 |
116 | ///
117 | /// Generates a random target point for the ball based on the winning side.
118 | ///
119 | /// The side that won the previous round. Must be either Side.Left or Side.Right.
120 | /// A Vector2 representing the random target point on the winning side.
121 | private Vector2 GetRandomTargetForDirection(Side winningSide) {
122 | Tuple corners = winningSide switch {
123 | Side.Left => this._leftSide,
124 | Side.Right => this._rightSide,
125 | _ => throw new ArgumentOutOfRangeException(nameof(winningSide), winningSide, null)
126 | };
127 | float randomTarget = Random.Shared.Next((int)corners.Item1.Y, (int)corners.Item2.Y);
128 | return corners.Item1 with { Y = randomTarget };
129 | }
130 |
131 | ///
132 | /// The Side enum represents the sides in the Pong game.
133 | ///
134 | private enum Side {
135 | Left,
136 | Right
137 | }
138 |
139 | public void Dispose() {
140 | Logger.SetTraceLogLevel(TraceLogLevel.All);
141 | Window.Close();
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: Build Raylib-CSharp
2 |
3 | on:
4 | release:
5 | types: [ "published" ]
6 | push:
7 | branches: [ "main" ]
8 | pull_request:
9 | branches: [ "main" ]
10 |
11 | env:
12 | raylib_version: '5.5'
13 |
14 | jobs:
15 |
16 | # Build for Win
17 | build-win:
18 | runs-on: windows-latest
19 | strategy:
20 | matrix:
21 | name: [win32, x64]
22 |
23 | # Run
24 | steps:
25 | - uses: actions/checkout@v4
26 |
27 | # Setup .NET
28 | - name: Setup .NET
29 | uses: actions/setup-dotnet@v4
30 | with:
31 | dotnet-version: 8.0.x
32 |
33 | # Build Raylib
34 | - name: Build Raylib
35 | shell: bash
36 | run: |
37 | curl -Lso raylib.zip https://github.com/raysan5/raylib/archive/refs/tags/${{ env.raylib_version }}.zip
38 | unzip -qq raylib.zip
39 | cmake -S raylib-${{ env.raylib_version }} \
40 | -A ${{ matrix.name }} \
41 | -B native \
42 | -D CMAKE_BUILD_TYPE=Release \
43 | -D BUILD_SHARED_LIBS=ON \
44 | -D BUILD_EXAMPLES=OFF \
45 | -D CUSTOMIZE_BUILD=ON \
46 | -D SUPPORT_GIF_RECORDING=OFF \
47 | -D SUPPORT_SCREEN_CAPTURE=OFF \
48 | -D GRAPHICS=GRAPHICS_API_OPENGL_43
49 | cmake --build native --config Release
50 |
51 | # Upload Raylib
52 | - name: Upload Raylib
53 | uses: actions/upload-artifact@v4
54 | with:
55 | name: win-${{ matrix.name }}
56 | path: native/raylib/Release/raylib.dll
57 | if-no-files-found: error
58 |
59 | # Build for Linux
60 | build-linux:
61 | runs-on: ubuntu-latest
62 | strategy:
63 | matrix:
64 | name: [x64]
65 |
66 | # Run
67 | steps:
68 | - uses: actions/checkout@v4
69 |
70 | # Setup .NET
71 | - name: Setup .NET
72 | uses: actions/setup-dotnet@v4
73 | with:
74 | dotnet-version: 8.0.x
75 |
76 | # Setup dependencies
77 | - name: Setup dependencies
78 | run: |
79 | sudo apt-get install -y \
80 | libglfw3 \
81 | libglfw3-dev \
82 | libx11-dev \
83 | libxcursor-dev \
84 | libxrandr-dev \
85 | libxinerama-dev \
86 | libxi-dev \
87 | libxext-dev \
88 | libxfixes-dev \
89 | libwayland-dev \
90 | libwayland-bin \
91 | libxkbcommon-dev
92 |
93 | # Build Raylib
94 | - name: Build Raylib
95 | run: |
96 | curl -Lso raylib.zip https://github.com/raysan5/raylib/archive/refs/tags/${{ env.raylib_version }}.zip
97 | unzip -qq raylib.zip
98 | cmake -S raylib-${{ env.raylib_version }} \
99 | -B native \
100 | -D CMAKE_BUILD_TYPE=Release \
101 | -D BUILD_SHARED_LIBS=ON \
102 | -D BUILD_EXAMPLES=OFF \
103 | -D CUSTOMIZE_BUILD=ON \
104 | -D SUPPORT_GIF_RECORDING=OFF \
105 | -D SUPPORT_SCREEN_CAPTURE=OFF \
106 | -D GRAPHICS=GRAPHICS_API_OPENGL_43
107 | cmake --build native --config Release
108 |
109 | # Upload Raylib
110 | - name: Upload Raylib
111 | uses: actions/upload-artifact@v4
112 | with:
113 | name: linux-${{ matrix.name }}
114 | path: native/raylib/libraylib.so
115 | if-no-files-found: error
116 |
117 | # Build for OSX
118 | build-osx:
119 | runs-on: macos-latest
120 | strategy:
121 | matrix:
122 | name: [arm64, x86_64]
123 |
124 | # Run
125 | steps:
126 | - uses: actions/checkout@v4
127 |
128 | # Setup .NET
129 | - name: Setup .NET
130 | uses: actions/setup-dotnet@v4
131 | with:
132 | dotnet-version: 8.0.x
133 |
134 | # Build Raylib
135 | - name: Build Raylib
136 | run: |
137 | curl -Lso raylib.zip https://github.com/raysan5/raylib/archive/refs/tags/${{ env.raylib_version }}.zip
138 | unzip -qq raylib.zip
139 | cmake -S raylib-${{ env.raylib_version }} \
140 | -B native \
141 | -D CMAKE_BUILD_TYPE=Release \
142 | -D CMAKE_OSX_ARCHITECTURES=${{ matrix.name }} \
143 | -D BUILD_SHARED_LIBS=ON \
144 | -D BUILD_EXAMPLES=OFF \
145 | -D CUSTOMIZE_BUILD=ON \
146 | -D SUPPORT_GIF_RECORDING=OFF \
147 | -D SUPPORT_SCREEN_CAPTURE=OFF
148 | cmake --build native --config Release
149 |
150 | # Upload Raylib
151 | - name: Upload Raylib
152 | uses: actions/upload-artifact@v4
153 | with:
154 | name: osx-${{ matrix.name }}
155 | path: native/raylib/libraylib.dylib
156 | if-no-files-found: error
157 |
158 | # Publish to NuGet
159 | publish-nuget:
160 | runs-on: ubuntu-latest
161 | needs: [build-win, build-linux, build-osx]
162 |
163 | # Run
164 | steps:
165 | - uses: actions/checkout@v4
166 |
167 | # Setup .NET
168 | - name: Setup .NET
169 | uses: actions/setup-dotnet@v4
170 | with:
171 | dotnet-version: 8.0.x
172 |
173 | # Setup dependencies
174 | - name: Setup dependencies
175 | run: |
176 | sudo apt-get install -y \
177 | libglfw3 \
178 | libglfw3-dev \
179 | libx11-dev \
180 | libxcursor-dev \
181 | libxrandr-dev \
182 | libxinerama-dev \
183 | libxi-dev \
184 | libxext-dev \
185 | libxfixes-dev \
186 | libwayland-dev \
187 | libwayland-bin \
188 | libxkbcommon-dev
189 |
190 | # Windows x86
191 | - uses: actions/download-artifact@v4
192 | with:
193 | name: win-win32
194 | path: src/Raylib-CSharp/runtimes/win-x86/native
195 |
196 | # Windows x64
197 | - uses: actions/download-artifact@v4
198 | with:
199 | name: win-x64
200 | path: src/Raylib-CSharp/runtimes/win-x64/native
201 |
202 | # Linux x64
203 | - uses: actions/download-artifact@v4
204 | with:
205 | name: linux-x64
206 | path: src/Raylib-CSharp/runtimes/linux-x64/native
207 |
208 | # OSX arm64
209 | - uses: actions/download-artifact@v4
210 | with:
211 | name: osx-arm64
212 | path: src/Raylib-CSharp/runtimes/osx-arm64/native
213 |
214 | # OSX x64
215 | - uses: actions/download-artifact@v4
216 | with:
217 | name: osx-x86_64
218 | path: src/Raylib-CSharp/runtimes/osx-x64/native
219 |
220 | # Build and pack NuGet package
221 | - name: Build and pack NuGet package
222 | if: github.event_name == 'release'
223 | run: dotnet pack src/Raylib-CSharp -p:PackageVersion=${{ github.event.release.tag_name }} --configuration Release --output nuget
224 |
225 | # Publish NuGet package
226 | - name: Publish NuGet package
227 | if: github.event_name == 'release'
228 | run: dotnet nuget push nuget/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
229 |
--------------------------------------------------------------------------------
/src/Raylib-CSharp/Geometry/Model.cs:
--------------------------------------------------------------------------------
1 | using System.Numerics;
2 | using System.Runtime.InteropServices;
3 | using Raylib_CSharp.Collision;
4 | using Raylib_CSharp.Colors;
5 | using Raylib_CSharp.Materials;
6 | using Raylib_CSharp.Shaders;
7 | using Raylib_CSharp.Textures;
8 | using Raylib_CSharp.Transformations;
9 | using Raylib_CSharp.Apis;
10 |
11 | namespace Raylib_CSharp.Geometry;
12 |
13 | [StructLayout(LayoutKind.Sequential)]
14 | public struct Model {
15 |
16 | ///
17 | /// Local transform matrix.
18 | ///
19 | public Matrix4x4 Transform;
20 |
21 | ///
22 | /// Number of meshes.
23 | ///
24 | public int MeshCount;
25 |
26 | ///
27 | /// Number of materials.
28 | ///
29 | public int MaterialCount;
30 |
31 | ///
32 | /// Meshes array.
33 | ///
34 | public unsafe Mesh* MeshesPtr;
35 |
36 | ///
37 | public unsafe Span Meshes => new(this.MeshesPtr, this.MeshCount);
38 |
39 | ///
40 | /// Materials array.
41 | ///
42 | public unsafe Material* MaterialsPtr;
43 |
44 | ///
45 | public unsafe Span Materials => new(this.MaterialsPtr, this.MaterialCount);
46 |
47 | ///
48 | /// Mesh material number.
49 | ///
50 | public unsafe int* MeshMaterialPtr;
51 |
52 | ///
53 | public unsafe Span MeshMaterial => new(this.MeshMaterialPtr, this.MeshCount);
54 |
55 | ///
56 | /// Number of bones.
57 | ///
58 | public int BoneCount;
59 |
60 | ///
61 | /// Bones information (skeleton).
62 | ///
63 | public unsafe BoneInfo* BonesPtr;
64 |
65 | ///
66 | public unsafe Span Bones => new(this.BonesPtr, this.BoneCount);
67 |
68 | ///
69 | /// Bones base transformation (pose).
70 | ///
71 | public unsafe Transform* BindPosePtr;
72 |
73 | ///
74 | public unsafe Span BindPose => new(this.BindPosePtr, this.BoneCount);
75 |
76 | ///
77 | public static Model Load(string fileName) {
78 | return RaylibApi.LoadModel(fileName);
79 | }
80 |
81 | ///
82 | public static Model LoadFromMesh(Mesh mesh) {
83 | return RaylibApi.LoadModelFromMesh(mesh);
84 | }
85 |
86 | ///
87 | public static bool CheckCollisionSpheres(Vector3 center1, float radius1, Vector3 center2, float radius2) {
88 | return RaylibApi.CheckCollisionSpheres(center1, radius1, center2, radius2);
89 | }
90 |
91 | ///
92 | public static bool CheckCollisionSpheres(BoundingBox box1, BoundingBox box2) {
93 | return RaylibApi.CheckCollisionBoxes(box1, box2);
94 | }
95 |
96 | ///
97 | public static bool CheckCollisionSpheres(BoundingBox box, Vector3 center, float radius) {
98 | return RaylibApi.CheckCollisionBoxSphere(box, center, radius);
99 | }
100 |
101 | ///
102 | public static RayCollision GetRayCollisionSphere(Ray ray, Vector3 center, float radius) {
103 | return RaylibApi.GetRayCollisionSphere(ray, center, radius);
104 | }
105 |
106 | ///
107 | public static RayCollision GetRayCollisionBox(Ray ray, BoundingBox box) {
108 | return RaylibApi.GetRayCollisionBox(ray, box);
109 | }
110 |
111 | ///
112 | public static RayCollision GetRayCollisionMesh(Ray ray, Mesh mesh, Matrix4x4 transform) {
113 | return RaylibApi.GetRayCollisionMesh(ray, mesh, transform);
114 | }
115 |
116 | ///
117 | public static RayCollision GetRayCollisionTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3) {
118 | return RaylibApi.GetRayCollisionTriangle(ray, p1, p2, p3);
119 | }
120 |
121 | ///
122 | public static RayCollision GetRayCollisionQuad(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4) {
123 | return RaylibApi.GetRayCollisionQuad(ray, p1, p2, p3, p4);
124 | }
125 |
126 | ///
127 | public bool IsValid() {
128 | return RaylibApi.IsModelValid(this);
129 | }
130 |
131 | ///
132 | public void Unload() {
133 | RaylibApi.UnloadModel(this);
134 | }
135 |
136 | ///
137 | public BoundingBox GetBoundingBox() {
138 | return RaylibApi.GetModelBoundingBox(this);
139 | }
140 |
141 | ///
142 | public void SetMeshMaterial(int meshId, int materialId) {
143 | RaylibApi.SetModelMeshMaterial(ref this, meshId, materialId);
144 | }
145 |
146 | ///
147 | /// Sets the shader for a specific material in the model.
148 | ///
149 | /// The index of the material within the model.
150 | /// The shader to set for the material.
151 | public void SetMaterialShader(int materialIndex, Shader shader) {
152 | this.Materials[materialIndex].Shader = shader;
153 | }
154 |
155 | ///
156 | /// Sets the texture of a material map in a model.
157 | ///
158 | /// The index of the material.
159 | /// The index of the material map.
160 | /// The texture to set.
161 | public void SetMaterialTexture(int materialIndex, MaterialMapIndex mapIndex, Texture2D texture) {
162 | this.Materials[materialIndex].Maps[(int)mapIndex].Texture = texture;
163 | }
164 |
165 | ///
166 | /// Sets the color of a material map for a specific model.
167 | ///
168 | /// The index of the material within the model.
169 | /// The index of the material map within the material.
170 | /// The color to set for the material map.
171 | public void SetMaterialColor(int materialIndex, MaterialMapIndex mapIndex, Color color) {
172 | this.Materials[materialIndex].Maps[(int)mapIndex].Color = color;
173 | }
174 |
175 | ///
176 | /// Sets the value of a material map in a model.
177 | ///
178 | /// The index of the material containing the map.
179 | /// The index of the material map to modify.
180 | /// The new value to assign to the material map.
181 | public void SetMaterialValue(int materialIndex, MaterialMapIndex mapIndex, float value) {
182 | this.Materials[materialIndex].Maps[(int)mapIndex].Value = value;
183 | }
184 | }
--------------------------------------------------------------------------------
/src/Raylib-CSharp/IO/FileManager.cs:
--------------------------------------------------------------------------------
1 | using System.Text;
2 | using Raylib_CSharp.Apis;
3 |
4 | namespace Raylib_CSharp.IO;
5 |
6 | public static class FileManager {
7 |
8 | ///
9 | public static unsafe ReadOnlySpan LoadFileData(string fileName) {
10 | return new ReadOnlySpan(RaylibApi.LoadFileData(fileName, out uint dataSize), (int)dataSize);
11 | }
12 |
13 | ///
14 | public static unsafe void UnloadFileData(ReadOnlySpan data) {
15 | fixed (byte* dataPtr = data) {
16 | RaylibApi.UnloadFileData(dataPtr);
17 | }
18 | }
19 |
20 | ///
21 | public static unsafe bool SaveFileData(string fileName, ReadOnlySpan data) {
22 | fixed (byte* dataPtr = data) {
23 | return RaylibApi.SaveFileData(fileName, (nint)dataPtr, (uint)data.Length);
24 | }
25 | }
26 |
27 | ///
28 | public static unsafe bool ExportDataAsCode(ReadOnlySpan data, string fileName) {
29 | fixed (byte* dataPtr = data) {
30 | return RaylibApi.ExportDataAsCode(dataPtr, (uint)data.Length, fileName);
31 | }
32 | }
33 |
34 | ///
35 | public static string LoadFileText(string fileName) {
36 | return RaylibApi.LoadFileText(fileName);
37 | }
38 |
39 | ///
40 | public static void UnloadFileText(string text) {
41 | RaylibApi.UnloadFileText(text);
42 | }
43 |
44 | ///
45 | public static bool SaveFileText(string fileName, string text) {
46 | return RaylibApi.SaveFileText(fileName, text);
47 | }
48 |
49 | ///
50 | public static bool FileExists(string fileName) {
51 | return RaylibApi.FileExists(fileName);
52 | }
53 |
54 | ///
55 | public static bool DirectoryExists(string dirPath) {
56 | return RaylibApi.DirectoryExists(dirPath);
57 | }
58 |
59 | ///
60 | public static bool IsFileExtension(string fileName, string ext) {
61 | return RaylibApi.IsFileExtension(fileName, ext);
62 | }
63 |
64 | ///
65 | public static int GetFileLength(string fileName) {
66 | return RaylibApi.GetFileLength(fileName);
67 | }
68 |
69 | ///
70 | public static string GetFileExtension(string fileName) {
71 | return RaylibApi.GetFileExtension(fileName);
72 | }
73 |
74 | ///
75 | public static string GetFileName(string filePath) {
76 | return RaylibApi.GetFileName(filePath);
77 | }
78 |
79 | ///
80 | public static string GetFileNameWithoutExt(string filePath) {
81 | return RaylibApi.GetFileNameWithoutExt(filePath);
82 | }
83 |
84 | ///
85 | public static string GetDirectoryPath(string filePath) {
86 | return RaylibApi.GetDirectoryPath(filePath);
87 | }
88 |
89 | ///
90 | public static string GetPrevDirectoryPath(string dirPath) {
91 | return RaylibApi.GetPrevDirectoryPath(dirPath);
92 | }
93 |
94 | ///
95 | public static string GetWorkingDirectory() {
96 | return RaylibApi.GetWorkingDirectory();
97 | }
98 |
99 | ///
100 | public static string GetApplicationDirectory() {
101 | return RaylibApi.GetApplicationDirectory();
102 | }
103 |
104 | ///
105 | public static bool ChangeDirectory(string dir) {
106 | return RaylibApi.ChangeDirectory(dir);
107 | }
108 |
109 | ///
110 | public static bool MakeDirectory(string dir) {
111 | return RaylibApi.MakeDirectory(dir);
112 | }
113 |
114 | ///
115 | public static bool IsPathFile(string path) {
116 | return RaylibApi.IsPathFile(path);
117 | }
118 |
119 | ///
120 | public static bool IsFileNameValid(string fileName) {
121 | return RaylibApi.IsFileNameValid(fileName);
122 | }
123 |
124 | ///
125 | public static FilePathList LoadDirectoryFiles(string dirPath) {
126 | return RaylibApi.LoadDirectoryFiles(dirPath);
127 | }
128 |
129 | ///
130 | public static FilePathList LoadDirectoryFilesEx(string basePath, string filter, bool scanSubDirs) {
131 | return RaylibApi.LoadDirectoryFilesEx(basePath, filter, scanSubDirs);
132 | }
133 |
134 | ///
135 | public static void UnloadDirectoryFiles(FilePathList files) {
136 | RaylibApi.UnloadDirectoryFiles(files);
137 | }
138 |
139 | ///
140 | public static bool IsFileDropped() {
141 | return RaylibApi.IsFileDropped();
142 | }
143 |
144 | ///
145 | public static FilePathList LoadDroppedFiles() {
146 | return RaylibApi.LoadDroppedFiles();
147 | }
148 |
149 | ///
150 | public static void UnloadDroppedFiles(FilePathList files) {
151 | RaylibApi.UnloadDroppedFiles(files);
152 | }
153 |
154 | ///
155 | public static long GetFileModTime(string fileName) {
156 | return RaylibApi.GetFileModTime(fileName);
157 | }
158 |
159 | ///
160 | public static unsafe ReadOnlySpan CompressData(ReadOnlySpan data) {
161 | fixed (byte* dataPtr = data) {
162 | return new ReadOnlySpan(RaylibApi.CompressData(dataPtr, data.Length, out int compDataSize), compDataSize);
163 | }
164 | }
165 |
166 | ///
167 | public static unsafe ReadOnlySpan DecompressData(ReadOnlySpan compData) {
168 | fixed (byte* compDataPtr = compData) {
169 | return new ReadOnlySpan(RaylibApi.DecompressData(compDataPtr, compData.Length, out int dataSize), dataSize);
170 | }
171 | }
172 |
173 | ///
174 | public static unsafe string EncodeDataBase64(ReadOnlySpan data, out int outputSize) {
175 | fixed (byte* dataPtr = data) {
176 | return RaylibApi.EncodeDataBase64(dataPtr, data.Length, out outputSize);
177 | }
178 | }
179 |
180 | ///
181 | public static unsafe ReadOnlySpan DecodeDataBase64(ReadOnlySpan data) {
182 | fixed (byte* dataPtr = data) {
183 | return new ReadOnlySpan(RaylibApi.DecodeDataBase64(dataPtr, out int outputSize), outputSize);
184 | }
185 | }
186 | ///
187 | public static unsafe uint ComputeCRC32(ReadOnlySpan data) {
188 | fixed (byte* dataPtr = data) {
189 | return RaylibApi.ComputeCRC32(dataPtr, data.Length);
190 | }
191 | }
192 | ///
193 | public static unsafe uint[] ComputeMD5(ReadOnlySpan data) {
194 | fixed (byte* dataPtr = data) {
195 | uint* nativeResult = RaylibApi.ComputeMD5(dataPtr, data.Length);
196 | uint[] convertedResult = new uint[4];
197 | for (int ptrIndex = 0; ptrIndex < 4; ptrIndex++) { convertedResult[ptrIndex] = nativeResult[ptrIndex]; }
198 | return convertedResult;
199 | }
200 | }
201 | ///
202 | public static unsafe uint[] ComputeSHA1(ReadOnlySpan data) {
203 | fixed (byte* dataPtr = data) {
204 | uint* nativeResult = RaylibApi.ComputeSHA1(dataPtr, data.Length);
205 | uint[] convertedResult = new uint[5];
206 | for (int ptrIndex = 0; ptrIndex < 5; ptrIndex++) { convertedResult[ptrIndex] = nativeResult[ptrIndex]; }
207 | return convertedResult;
208 | }
209 | }
210 | }
--------------------------------------------------------------------------------