Giter Site home page Giter Site logo

chrisdill / raylib-cs Goto Github PK

View Code? Open in Web Editor NEW
686.0 24.0 68.0 77.58 MB

C# bindings for raylib, a simple and easy-to-use library to learn videogames programming

Home Page: http://www.raylib.com/

License: zlib License

C# 100.00%
raylib csharp binding gamedev

raylib-cs's Introduction

Raylib-cs Logo

Raylib-cs

C# bindings for raylib, a simple and easy-to-use library to learn videogames programming (www.raylib.com)

GitHub contributors License

Chat on Discord GitHub stars

Build

Raylib-cs targets net5.0 and net6.0 and uses the official 5.0 release to build the native libraries.

Installation - NuGet

This is the prefered method to get started.

  1. Pick a folder in which you would like to start a raylib project for example "MyRaylibCSProj"
  2. Then from a terminal (for example a VSCode terminal), whilst in the folder dir you just created run the following commands. (Please keep in mind you should have .NET already installed on your system)
dotnet new console
dotnet add package Raylib-cs

NuGet

If you need to edit Raylib-cs source then you will need to add the bindings as a project (see below).

If you are new to using NuGet (or you've forgotten) and are trying to run the above command in the command prompt, remember that you need to be inside the intended project directory (not just inside the solution directory) otherwise the command won't work.

Installation - Manual

  1. Download/clone the repo

  2. Add Raylib-cs/Raylib-cs.csproj to your project as an existing project.

  3. Download the native libraries for the platforms you want to build for using the official 5.0 release. NOTE: the MSVC version is required for Windows platforms

  4. Setup the native libraries so they are in the same directory as the executable/can be found in the search path.

  5. Start coding!

Hello, World!

using Raylib_cs;

namespace HelloWorld;

class Program
{
    public static void Main()
    {
        Raylib.InitWindow(800, 480, "Hello World");

        while (!Raylib.WindowShouldClose())
        {
            Raylib.BeginDrawing();
            Raylib.ClearBackground(Color.White);

            Raylib.DrawText("Hello, world!", 12, 12, 20, Color.Black);

            Raylib.EndDrawing();
        }

        Raylib.CloseWindow();
    }
}

Contributing

If you have any ideas, feel free to open an issue and tell me what you think. If you'd like to contribute, please fork the repository and make changes as you'd like. Pull requests are warmly welcome.

If you want to request features or report bugs related to raylib directly (in contrast to this binding), please refer to the author's project repo.

License

See LICENSE for details.

raylib-cs's People

Contributors

9parsonsb avatar anggape avatar benbeshara avatar chrisdill avatar danilwhale avatar fallbork avatar germanhoyos avatar graphnode avatar jarroddoyle avatar jupiterrider avatar lazaroblanc avatar metlhedd avatar mrscauthd avatar msmshazan avatar nailuj29 avatar nickymcdonald avatar njlr avatar spec-chum avatar tylerdm avatar wraithglade avatar yxure avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

raylib-cs's Issues

Add netcore support

Project has currently been tested with .net framework and mono.
Using netcore could provide a better cross platform alternative.

Haven't used it before so any useful links would help. :)
Would involve supporting multiple project types.

Fix MarshallAs issue with raylib structs

There are issues getting unmanaged arrays with a fixed size to work in C#. I have had errors with using LoadShader throwing error "Method's type signature is not PInvoke compatible".

I am not sure what I am doing wrong.
Here are the structs using MarshallAs currently and the array from C.

  • Mesh unsigned int vboId[7];
  • Shader int locs[MAX_SHADER_LOCATIONS];
  • Material MaterialMap maps[MAX_MATERIAL_MAPS];

Unable to find an entry point named 'InitPhysics' in DLL 'libraylib'

Running the demos with the latest 2.5 release and all of them are working fine except for the physics examples. These all throw the same unhandled exception on InitPhysics.

Exception User-Unhandled
System.EntryPointNotFoundException: 'Unable to find an entry point named 'InitPhysics' in DLL 'libraylib'.'
  at Raylib.Raylib.InitPhysics()
   at physics_demo.Main() in C:\raylib\Raylib-cs\Examples\physac\physics_demo.cs:line 41

Tried a few things like setting exactspelling to false for the dll import, and adding a reference to the dll in the csproj file, but to no avail.

I'm running the demos with the Test.NetCore app and using the mingw dll ( the msvc15 version threw the same EntryPointNotFound exception on ChangeDirectory(), which made it impossible to run any demo at all ).

Raylib DLL's do not export necessary functions

The most up to date raylib binaries do not contain the correct exports for certain core functions such as InitWindow(). This may require a native wrapper with the correct exports to be built into a new library.

Eg;

INTERNAL bool InitWindow(int width, int height, const char* title);
// should be wrapped with
bool __declspec(dllexport) InitWindow(int width, int height, const* title) {
        InitWindow(width, height, title);
}

This wrapper code could then be built against a static lib of raylib to result in a single, correctly built, dll file.

Strange issue with RenderTexture

Hey. I'm just starting with Raylib and the C# Binding and seem to be having an issue with Render Textures.

I'm on a macOS 10.15.4 application is .NET Core 3.1

I create a texture the same size as the screen based on the examples when I draw it the size is off and if I move the window the my second monitor it zooms right into the bottom left corner.

            TemporaryA = Raylib.LoadRenderTexture(1024, 768);

             BeginTextureMode(EngineBuffers.TemporaryA);
             ClearBackground(Color.RED);
                
             //DrawTextureEx(Texture, position, rotation, scale, Fade(color, opacity));
                
             EndTextureMode();

             DrawTextureRec(EngineBuffers.TemporaryA.texture, new Rectangle(0, 0, 1024, -768), new Vector2(0, 0), Color.WHITE);

Will result in drawing:

Screenshot 2020-05-10 at 17 33 46

When moving the game window to the second monitor when using a render texture (it's fine if I don't use any render textures):

Screenshot 2020-05-10 at 17 34 02

Handle x86 and x64 bit version of raylib

Currently using a custom build of raylib for x64 bit but also want to support x86.
Need a way for the bindings to use both. They currently look for a file called raylib.dll in the same directory as the .exe.

Maybe copy the dll at build or runtime based on the architecture used?

Unable to load textures

I'm trying to load a texture and it gives me an error saying: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt".
I also tried the examples and I get no error but in the console it says "WARNING: [resources/texture.png] failed to load" and the texture doesn't show, fonts, 3d object, ... works fine, it's just textures

DllNotFoundException

Hi,

I have read the README.MD in detail, I have downloaded from the GIT of raylib the release for windows x64 bits and windows x32 both msvc15.

The dll that is in the bin folder, I have copied it in a multitude of parts because nowhere has he achive to find the DLL.

I have copied it to system32
I have copied it to system
In the root of the project
In the root of the executable project

And there is no way to find the DLL

Im using Visual Studio 2019

Could you please help me?

Thank you

embed raylib unmanaged c++ library in C# managed library

please embed the unmanaged c++ raylib library into a managed C# library.
I would recommend a .net framework and .net core version.

https://github.com/Fody/Costura.

this makes it easier on developers using your library and also allows people to static link their own libraries easier.

this would also make it easier to upload to nuget and overall make the users project and application cleaner.

Improving code generation

I have tried a few different ways to generate binding code to make sure the bindings can stay up to date with the original. This post will be updated on the current state of the issue to hopefully make things clearer.

What has been tried so far?

CppSharp generator

  • Close to what I wanted but a few issues with the output not being minimal and readable compared to what I had manually made.

Roslyn generator

  • Contributed by @msmshazan, it is the generator currently included. I did find Roslyn a bit verbose and hard to add features to. Need to look into it more.

CppAST generator

  • I saw this library that helps with the parsing and gave it a try. It works quite well and got me the most of the way. I had a few issues getting comments to align the way I wanted but it looks promising.

Custom raylib tool

NuGet package does not work in most configurations

I am trying to use Raylib-cs with fsharp on dotnet 3.1.

I am able to install the lib on a console app using dotnet add Raylib-cs
But now in my code doing
open Raylib
gives me the error The namespace or module 'Raylib' is not defined.

Why are are there no examples of how to do some things in C#

Hey,
why are there no examples of how to do some things in C#
For example I'm stuck with the following example
grafik

Why is CreatePhysicsBody returning IntPtr? I don't even know what that is.
grafik
In normal Raylib it seems realy simple
And yes I've read your comment about what IntPtr referes to
grafik
But I still have no fucking idea how to use that in real world.

Sry if I'm a bit harsh, but I'm just mentally broken right now, because I switched between c and C# 5 times last week.
I know that you are doing great work, but I would be so greatful if you could help me with that.
ǎ̷̢̢̛͈̯̟͇͇̘̞̝̲͎̦̰̦̘͙͖̤̻̩̯̻̪̗̔̀̊͐͗̀͂́̀̄̄͆͌͛̏̿̑́̇̈́̚͘͜͝͠

The Fade function does not exist in Raylib.cs

I expect this code is missing in the Raylib.cs file

    [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
    public static extern Color Fade(Color color, float alpha);

Raylib.Raylib.DrawTriangleStrip does not exist

this doesn't work due to DrawTriangleStrip not being implemented.

        public static void Line(bool fill, uint col, params float[] points)
        {
            if ((points.Length % 2) != 0)
            {
                Console.WriteLine("Cannot draw without multipule of two points");
                return;
            }

            Vector2[] points2 = new Vector2[points.Length / 2];
            for (var i=0; i< points.Length; i+=2)
            {
                points2[i/2] = new Vector2(points[i+0], points[i+1]);
            }

            Col(col);

            if (fill) Raylib.Raylib.DrawTriangleFan  (points2, points2.Length, _col);
            else      Raylib.Raylib.DrawTriangleStrip(points2, points2.Length, _col);       
        }

error on run

Hi
sorry this is not an issue but I dont know how to send you a message , please help me
I downloaded Raylib and I instaled it , then I downloaded this project and compiled it
I got an error :
System.DllNotFoundException: 'Unable to load DLL 'raylib': The specified module could not be found. (Exception from HRESULT: 0x8007007E)'
how to run this project ? do I need to compile Raylib to run it whith c# ? ,how to do so ? how to get dlls files and how to add and use them with the project ?
I want to run Raylib inside winform application , how to make viewport display on a panel or form for example ?
Please help me ,Thank You very Much

Raylib 3.1.6 crashes upon loading obj file

when loading in an obj file, the program crashes without warning and without any sort of error messages as shown below:
image
The program stops right after raylib outputs that it loaded obj data successfully. The model in question also loads fine within other applications, like blender, and the program also runs fine if the models aren't loaded in at all.

FormatText function missing

In raylib v2.0.0 quick reference card there is a FormatText function described like this:
const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed'
and here it is missing

Add Raygui to nuget package

I tried copying the raygui.cs to my project so I could use it however It throws dll not found exception for raylib

using System.Numerics;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using Raylib_cs;

namespace Raygui_cs
{
    // Style property
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    struct GuiStyleProp
    {
        ushort controlId;
        ushort propertyId;
        int propertyValue;
    }

    // Gui global state enum
    public enum GuiControlState
    {
        GUI_STATE_NORMAL = 0,
        GUI_STATE_FOCUSED,
        GUI_STATE_PRESSED,
        GUI_STATE_DISABLED,
    }

    // Gui global text alignment
    public enum GuiTextAlignment
    {
        GUI_TEXT_ALIGN_LEFT = 0,
        GUI_TEXT_ALIGN_CENTER,
        GUI_TEXT_ALIGN_RIGHT,
    }

    // Gui standard controls
    public enum GuiControlStandard
    {
        DEFAULT = 0,
        LABEL,          // LABELBUTTON
        BUTTON,         // IMAGEBUTTON
        TOGGLE,         // TOGGLEGROUP
        SLIDER,         // SLIDERBAR
        PROGRESSBAR,
        CHECKBOX,
        COMBOBOX,
        DROPDOWNBOX,
        TEXTBOX,        // TEXTBOXMULTI
        VALUEBOX,
        SPINNER,
        LISTVIEW,
        COLORPICKER,
        SCROLLBAR,
        STATUSBAR
    }

    // Gui default properties for every control
    public enum GuiControlProperty
    {
        BORDER_COLOR_NORMAL = 0,
        BASE_COLOR_NORMAL,
        TEXT_COLOR_NORMAL,
        BORDER_COLOR_FOCUSED,
        BASE_COLOR_FOCUSED,
        TEXT_COLOR_FOCUSED,
        BORDER_COLOR_PRESSED,
        BASE_COLOR_PRESSED,
        TEXT_COLOR_PRESSED,
        BORDER_COLOR_DISABLED,
        BASE_COLOR_DISABLED,
        TEXT_COLOR_DISABLED,
        BORDER_WIDTH,
        TEXT_PADDING,
        TEXT_ALIGNMENT,
        RESERVED
    }

    // Gui extended properties depending on control type
    // NOTE: We reserve a fixed size of additional properties per control

    // Default properties
    public enum GuiDefaultProperty
    {
        TEXT_SIZE = 16,
        TEXT_SPACING,
        LINE_COLOR,
        BACKGROUND_COLOR,
    }

    // Toggle / ToggleGroup
    public enum GuiToggleProperty
    {
        GROUP_PADDING = 16,
    }

    // Slider / SliderBar
    public enum GuiSliderProperty
    {
        SLIDER_WIDTH = 16,
        TEXT_PADDING
    }

    // ProgressBar
    public enum GuiProgressBarProperty
    {
        PROGRESS_PADDING = 16,
    }

    // CheckBox
    public enum GuiCheckBoxProperty
    {
        CHECK_PADDING = 16
    }

    // ComboBox
    public enum GuiComboBoxProperty
    {
        SELECTOR_WIDTH = 16,
        SELECTOR_PADDING
    }

    // DropdownBox
    public enum GuiDropdownBoxProperty
    {
        ARROW_PADDING = 16,
        DROPDOWN_ITEMS_PADDING
    }

    // TextBox / TextBoxMulti / ValueBox / Spinner
    public enum GuiTextBoxProperty
    {
        TEXT_INNER_PADDING = 16,
        TEXT_LINES_PADDING,
        COLOR_SELECTED_FG,
        COLOR_SELECTED_BG
    }

    // Spinner
    public enum GuiSpinnerProperty
    {
        SPIN_BUTTON_WIDTH = 16,
        SPIN_BUTTON_PADDING,
    }

    // ScrollBar
    public enum GuiScrollBarProperty
    {
        ARROWS_SIZE = 16,
        ARROWS_VISIBLE,
        SCROLL_SLIDER_PADDING,
        SCROLL_SLIDER_SIZE,
        SCROLL_PADDING,
        SCROLL_SPEED,
    }

    // ScrollBar side
    public enum GuiScrollBarSide
    {
        SCROLLBAR_LEFT_SIDE = 0,
        SCROLLBAR_RIGHT_SIDE
    }

    // ListView
    public enum GuiListViewProperty
    {
        LIST_ITEMS_HEIGHT = 16,
        LIST_ITEMS_PADDING,
        SCROLLBAR_WIDTH,
        SCROLLBAR_SIDE,
    }

    // ColorPicker
    public enum GuiColorPickerProperty
    {
        COLOR_SELECTOR_SIZE = 16,
        HUEBAR_WIDTH,                  // Right hue bar width
        HUEBAR_PADDING,                // Right hue bar separation from panel
        HUEBAR_SELECTOR_HEIGHT,        // Right hue bar selector height
        HUEBAR_SELECTOR_OVERFLOW       // Right hue bar selector overflow
    }

    [SuppressUnmanagedCodeSecurity]
    public static class Raygui
    {
        // Used by DllImport to load the native library.
        public const string nativeLibName = "raygui";

        public const string RAYGUI_VERSION = "2.6-dev";

        public const int NUM_CONTROLS = 16;                      // Number of standard controls
        public const int NUM_PROPS_DEFAULT = 16;                 // Number of standard properties
        public const int NUM_PROPS_EXTENDED = 8;                 // Number of extended properties

        public const int TEXTEDIT_CURSOR_BLINK_FRAMES = 20;      // Text edit controls cursor blink timming

        // Global gui modification functions

        // Enable gui controls (global state)
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GuiEnable();

        // Disable gui controls (global state)
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GuiDisable();

        // Lock gui controls (global state)
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GuiLock();

        // Unlock gui controls (global state)
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GuiUnlock();

        // Set gui controls alpha (global state), alpha goes from 0.0f to 1.0f
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GuiFade(float alpha);

        // Set gui state (global state)
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GuiSetState(int state);

        // Get gui state (global state)
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern int GuiGetState();

        // Get gui custom font (global state)
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GuiSetFont(Font font);

        // Set gui custom font (global state)
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern Font GuiGetFont();


        // Style set/get functions

        // Set one style property
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GuiSetStyle(GuiControlStandard control, GuiControlProperty property, int value);

        // Get one style property
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern int GuiGetStyle(GuiControlStandard control, GuiControlProperty property);


        // Container/separator controls, useful for controls organization

        // Window Box control, shows a window that can be closed
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool GuiWindowBox(Rectangle bounds, string text);

        // Group Box control with title name
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GuiGroupBox(Rectangle bounds, string text);

        // Line separator control
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GuiLine(Rectangle bounds, string text);

        // Panel control, useful to group controls
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GuiPanel(Rectangle bounds);

        // Scroll Panel control
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern Rectangle GuiScrollPanel(Rectangle bounds, Rectangle content, ref Vector2 scroll);


        // Basic controls set

        // Label control, shows text
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GuiLabel(Rectangle bounds, string text);

        // Button control, returns true when clicked
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool GuiButton(Rectangle bounds, string text);

        // Label button control, show true when clicked
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool GuiLabelButton(Rectangle bounds, string text);

        // Image button control, returns true when clicked
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool GuiImageButton(Rectangle bounds, Texture2D texture);

        // Image button extended control, returns true when clicked
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool GuiImageButtonEx(Rectangle bounds, Texture2D texture, Rectangle texSource, string text);

        // Toggle Button control, returns true when active
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool GuiToggle(Rectangle bounds, string text, bool active);

        // Toggle Group control, returns active toggle index
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern int GuiToggleGroup(Rectangle bounds, string text, int active);

        // Check Box control, returns true when active
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool GuiCheckBox(Rectangle bounds, bool isChecked);

        // Combo Box control, returns selected item index
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern int GuiComboBox(Rectangle bounds, string text, int active);

        // Dropdown Box control, returns selected item
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool GuiDropdownBox(Rectangle bounds, string[] text, ref int active, bool edit);

        // Spinner control, returns selected value
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool GuiSpinner(Rectangle bounds, ref int value, int maxValue, int btnWidth);

        // Value Box control, updates input text with numbers
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool GuiValueBox(Rectangle bounds, int value, int maxValue);

        // Text Box control, updates input text
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool GuiTextBox(Rectangle bounds, StringBuilder text, int textSize, bool freeEdit);

        // Text Box control with multiple lines
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool GuiTextBoxMulti(Rectangle bounds, StringBuilder text, int textSize, bool editMode);

        // Slider control, returns selected value
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern float GuiSlider(Rectangle bounds, float value, float minValue, float maxValue, bool showValue);

        // Slider Bar control, returns selected value
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern float GuiSliderBar(Rectangle bounds, float value, float minValue, float maxValue, bool showValue);

        // Progress Bar control, shows current progress value
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern float GuiProgressBar(Rectangle bounds, float value, float minValue, float maxValue, bool showValue);

        // Progress Bar control, shows current progress value
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern float GuiProgressBarEx(Rectangle bounds, float value, float minValue, float maxValue, bool showValue);

        // Status Bar control, shows info text
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GuiStatusBar(Rectangle bounds, string text);

        // Dummy control for placeholders
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GuiDummyRec(Rectangle bounds, string text);

        // Scroll Bar control
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue);

        // Grid
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GuiGrid(Rectangle bounds, float spacing, int subdivs);


        // Advance controls set

        // List View control, returns selected list element index
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern int GuiListView(Rectangle bounds, string text, ref int active, ref int scrollIndex, bool editMode);

        // List View with extended parameters
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern int GuiListViewEx(Rectangle bounds, string text, int count, ref int enabled, ref int active, ref int focus, ref int scrollIndex, bool editMode);

        // Message Box control, displays a message
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool GuiMessageBox(Rectangle bounds, string windowTitle, string message);

        // Text Input Box control, ask for text
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool GuiTextInputBox(Rectangle bounds, string windowTitle, string message, string buttons);

        // Color Picker control
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern Color GuiColorPicker(Rectangle bounds, Color color);


        // Styles loading functions

        // Load style file (.rgs)
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern int GuiLoadStyle(string fileName);

        // Load style default over global style
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool GuiLoadStyleDefault();

        // Get text with icon id prepended
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern string GuiIconText(int iconId, string text);


        // Gui icons functionality

        // Get full icons data pointer
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern uint[] GuiGetIcons();

        // Get icon bit data
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern uint[] GuiGetIconData(int iconId, string text);

        // Set icon bit data
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GuiSetIconData(int iconId, uint[] data);

        // Set icon pixel value
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern string GuiSetIconPixel(int iconId, int x, int y);

        // Clear icon pixel value
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern string GuiClearIconPixel(int iconId, int x, int y);

        // Check icon pixel value
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
        public static extern string GuiCheckIconPixel(int iconId, int x, int y);
    }
}

Cant build

My setup is a raspberry Pi 3b+ running Raspbian Buster.

On the Pi I have installed dotnet core 2.2 and can create, build and run the standard Console "Hello World" app.

I have downloaded the "raylib-2.5.0-Linux-i386.tar.gz" library and placed "libraylib.so.2.5.0" in the root of my source directory as libraylib.so. Ive added the following to my csproj file:

  <Content Include="libraylib.so">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      </Content>
  </ItemGroup>

And can confirm that the file is copied to "bin/Debug/netcoreapp2.2".

I have copied the Binding directory into my project and run

dotnet run /p:AllowUnsafeBlocks=true

But I get the following error:

Unhandled Exception: System.DllNotFoundException: Unable to load shared library 'raylib' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libraylib: cannot open shared object file: No such file or directory
   at Raylib.Raylib.InitWindow(Int32 width, Int32 height, String title)
   at Program.Main() in /home/pi/clock/Program.cs:line 10

Here is the content of the directory:

pi@clock0:~/clock/bin/Debug/netcoreapp2.2 $ ls -la
total 2424
drwxr-xr-x 2 pi pi    4096 Aug 26 16:42 .
drwxr-xr-x 3 pi pi    4096 Aug 26 14:25 ..
-rw-r--r-- 1 pi pi     425 Aug 26 16:42 clock.deps.json
-rw-r--r-- 1 pi pi   64512 Aug 26 16:42 clock.dll
-rw-r--r-- 1 pi pi    9240 Aug 26 16:42 clock.pdb
-rw-r--r-- 1 pi pi     194 Aug 26 16:42 clock.runtimeconfig.dev.json
-rw-r--r-- 1 pi pi     146 Aug 26 16:42 clock.runtimeconfig.json
-rw-r--r-- 1 pi pi 2380509 May 31 19:09 libraylib.so

I even put the file in /usr/lib:

pi@clock0:/usr/lib $ ls -la libr*
-rwxrwxrwx 1 root root 2380509 Aug 26 14:11 libraylib.so

Any idea's?

Raygui

Hi
How do we get setup to use the bindings for RayGUI?

Missing a binary for raygui.dll?

3.0 plan

Preparing bindings for the release of raylib 3.0.

  • Reduce unsafe with features like Span I tested it on the Mesh arrays and it makes it easy to use it as a normal array, however I am not sure it is something that should be in the binding code directly. I am thinking of having a example showing how to use it though.

  • Improve generator so it can regenerate current bindings. See #29 for details on this. I have tried different approaches and work on this is ongoing.

The bindings are nearly automated so the hard part is updating all the examples. Help on this is greatly appreciated.

IsWindowMinimized() never runs

Raylib.IsWindowMinimized() in my main loop never returns true, no matter what I do with the window (minimizing, switching to another window to have it lose focus, etc.).

Perhaps I'm misunderstanding something. How am I supposed to handle losing focus? I'd like to pause the simulation while out of focus for obvious reasons.

Thank you!

(I'm using the 3.0 version.)

can't add package through package manager console

package manager doesn't work with this

PM> dotnet add Rouge package Raylib-cs
  Writing C:\Users\Shadowblitz16\AppData\Local\Temp\tmp4C7E.tmp
info : Adding PackageReference for package 'Raylib-cs' into project 'C:\Users\Shadowblitz16\Documents\Visual Studio 2019\Projects\Cs\Rouge\Rouge\Rouge.csproj'.
error: Error while adding package 'Raylib-cs' to project 'C:\Users\Shadowblitz16\Documents\Visual Studio 2019\Projects\Cs\Rouge\Rouge\Rouge.csproj'. The project does not support adding package references through the add package command.

Usage: NuGet.CommandLine.XPlat.dll package add [options]

Options:
  -h|--help               Show help information
  --force-english-output  Forces the application to run using an invariant, English-based culture.
  --package               Id of the package to be added.
  --version               Version of the package to be added.
  -d|--dg-file            Path to the dependency graph file to be used to restore preview and compatibility check.
  -p|--project            Path to the project file.
  -f|--framework          Frameworks for which the package reference should be added.
  -n|--no-restore         Do not perform restore preview and compatibility check. The added package reference will be unconditional.
  -s|--source             Specifies NuGet package sources to use during the restore.
  --package-directory     Directory to restore packages in.
  --interactive           Allow the command to block and require manual action for operations like authentication.

installing it through the gui doesn't work either since after I do it there is no raylib namespace
image

Provided solution can't find some projects

I tried downloading the repo and open provided solution, most of the projects contained can not be found. I tried adding Tests.MultiTarget.csproj but it fails on compilation, I get this error:

Error	NU1101	Unable to find package Microsoft.DotNet.ILCompiler. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages, nuget.org

Importing Diffuse texture and applying to a Mesh

Hi,

I'm trying to apply a texture to a mat but I could not figure out how to do it:

here is a succession of what I've tried:

a direct translation of the c code taken from examples:

m_LP_SpookyTree = LP_SpookyTree.GetModel;
m_LP_SpookyTree.materials[0].maps[MaterialMapType.MAP_ALBEDO].texture = Raylib.LoadTexture("Ressource/Textures/PlaceHolders/mossy_rock_diff_1k.png");

the last test

m_LP_SpookyTree = LP_SpookyTree.GetModel;
var mat = m_LP_SpookyTree.materials;
mat[0].maps[MaterialMapType.MAP_ALBEDO].texture = Raylib.LoadTexture("Ressource/Textures/PlaceHolders/mossy_rock_diff_1k.png");

The problem comes from the Intptr, how could I get the material array from it?

thanks for your time.

GetImageData as Color[]

Hi

I've been attempting to get a Color[] from the screen but not sure how to get the array of pixels from the ToPointer, just returns a single Color ?

var img = Raylib.GetScreenData();
var img2 = Raylib.GetImageData(img);
Color* mapPixels = (Color*)img2.ToPointer();

Float vs Double

I find that, when using Raylib-CS, I do a lot of casting between 32-bit float and 64-bit double.

In most applications on modern PCs, there's no reason to use 32-bit float instead of 64-bit double, since the execution time remains the same and you're only sacrificing precision. The big exception si if you need 32 bits for something, like some bit-shifting voodoo or micro-optimizations, but even then those aren't common or even good practice in .NET.

For Raylib itself, 32-bit float is great for cross-platform compatibility reasons, but for Raylib-CS would it be reasonable to substitute double for float in most cases, especially in Vector2 and Vector3?

Use the enums!

Is your feature request related to a problem? Please describe.
Many of the raylib bindings use e.g. an int as input parameter while still having a corresponding enum that doesn't seem to be used anywhere. Is this intentional?

enum KeyboardKey {...} // not used anywhere?
public static extern bool IsKeyPressed(int key);

Describe the solution you'd like
A method that uses the enum and simply casts the value to an int(or the appropriate type) and then calls the raylib method.
Perhaps even mark the raylib method as private to minimize confusion?

public static extern bool IsKeyPressed(KeyboardKey key) => IsKeyPressed((int)key);

If this seems like a good idea I'd be willing to create a pull request :)

Titlebar color doesn't match system theme (macOS)

Unlike in the C version of raylib which does this automatically, the c#/dotnet version of raylib does not automatically set the window titlebar color to fit the system theme. Instead, it's stuck on the light theme

Can not init a window in MacOS

Describe the bug
Can't Init a Window on MacOS. (System.DllNotFoundException)

To Reproduce
Install the Raylib-cs Nuget Package through Visual Studio Mac and write this piece of code.

using System;
using static Raylib.Raylib;

namespace myGame
{
    class MainClass
    {
        const string GAME_NAME = "My game";
        public static void Main()
        {
            int width = 800;
            int height = 400;
            InitWindow(width, height, GAME_NAME);
            SetTargetFPS(60);
        }
    }
}

Expected behavior
A window should be Initialized with the chosen size and title.

Details
System.DllNotFoundException: raylib
at at (wrapper managed-to-native) Raylib.Raylib.InitWindow(int,int,string)
at myGame.MainClass.Main () [0x0000d] in /Users/myname/Documents/Programmation/C#/myGame/myGame/Program.cs:13

Desktop

  • OS: MacOS Mojave 10.14.1

Memory leak.

Loading the library causes a huge memory leak on running the default project.

2.5 plan

Plan to update project for raylib 2.5.

  • Reduce unsafe with features like Span.
  • Support for mac and linux builds of raylib(.so .dylib) #19.
  • Decide how to support modules such as physac.
  • Improve generator so it can regenerate current bindings.
  • Highlight differences more clearly. #21 TextFormat etc.

Generating a Mesh

I'm attempting to implement Marching Cubes with Raylib-cs, but I ran into some serious problems trying to figure out how to properly create a Mesh struct. I started by trying to recreate Raylib's GenMeshCube() function in C#, and quickly ran into a lot of issues crossing between managed and unmanaged memory.

Is there a simpler way of doing this? Or would I be better off implementing this section in C?

Codepoints above 127 not rendering on Windows

DrawText as implemented in Raylib-cs only supports codepoints up to 127 in Windows – all characters above that gets rendered as "?". This is kind of annoying, as I'm a swedish programming teacher, and we have a few special extended ascii-characters; å, ä and ö are part of a lit of swedish words.

Things I've tried:

  • DrawText and DrawTextEx. Same result.
  • Loading different fonts, with or without explicit inclusion of codepoints up to 255. Same result.
  • Getting the latest Raylib-cs from the github page. Same result as with the nuget package.
  • Running the same code but in a virtual Debian machine. THIS WORKS, so issue seems to be in Windows.
  • Asking a friend who's proficient in C/C++ to try using åäö using Raylib in C++. THIS WORKS, so the issue seems to be specific to Raylib-cs, even though it's just a wrapper?
  • DrawTextCodepoint. THIS WORKS, which means that for some reason the issue is specific to the DrawText methods (and InitWindow). Raylib is supposed to be Unicode-capable, and this proves that at least in theory, it is.

Here's my simple test code (just writes out characters 0-255):

static void Main(string[] args)
{
  int font_size = 10;
  Raylib.InitWindow(800, font_size * 64, "åäö");
  while (!Raylib.WindowShouldClose())
  {
    Raylib.BeginDrawing();
    Raylib.ClearBackground(Color.BEIGE);
    for (int i = 0; i < 255; i++)
    {
      int col = i / 64;
      int x = col * 200;
      int y = (i % 64) * font_size;
      string text = i.ToString() + " | " + ((char)i).ToString();

      Raylib.DrawText(text, x, y, font_size, Color.BLACK);
    }
    Raylib.EndDrawing();
  }
}

It works fine in Debian, as stated, but in Windows columns 3 and 4 are filled with ?:s and the window titlebar is also just ???.

An nice fellow on StackOverflow, who definitely deems to know more than me about these kind of things, had this to say:

The way the library imports DrawText is faulty; its default behavior "marshals" string values to fit a legacy character encoding, not necessarily UTF-8: github.com/ChrisDill/Raylib-cs/blob/… . (Specifying CharSet=Unicode probably won't help because the DrawText function doesn't use wide-character strings, but rather ordinary char* pointers interpreted as UTF-8.)

(Peter O)

Loading OBJ File

Maybe I'm being dense, but I'm attempting to load an OBJ file as done in one of the examples and and running into an error.

Model model = LoadModel(@"monkey.obj");

monkey.zip

Attached is the OBJ file I'm trying to load. LoadModel throws a System.ExecutionEngineException. I've attempted different paths, including a full absolute path, but I get the same error no matter what I've tried.

Any suggestions?

Nuget release

  • Nuget package with no extra setup needed.
  • Reduce use of unsafe with features like Span.
  • Bundle mac and linux builds of raylib(.so .dylib ).
  • Add bindings to Rlgl.
  • Physac binding needs to be fixed.

Improving documentation

Discussion on the state of documentation for this library.

Code comments.

Using the same comments with the same style as raylib. One idea is to change them to the xmldoc style which can be used to generate external documentation. Unsure if this should be done but worth looking into.

Tech notes

Documenting api differences to make it easier for people new to raylib. Could move details like this into a seperate wiki page or file if needed. For example, a guide on how to handle/access IntPtr variables since Raylib-cs uses these in structs and functions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.