Git Product home page Git Product logo

raylib-ocaml's People

Contributors

lattay avatar mnxn avatar sjpgarcia avatar smorimoto avatar tjammer avatar willenbrink 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

raylib-ocaml's Issues

generate docstrings

I see in raylib_functions.ml that a lot of functions have a comment (extracted from C?) that describes what it does. However it's a (* foo *) comment, and just adding (** foo *) would make merlin/ocamllsp able to show the doc on hover 🙂

Package `raylib_c' not found

Any pointers on resolving this issue?

[22:04] ~/Code/fun/ocaml/raylib $ opam install raylib
[NOTE] Package raylib is already installed (current version is 0.3.2).
[22:04] ~/Code/fun/ocaml/raylib $ ocamlfind list | grep raylib
raylib              (version: 0.4.0)
raylib-gen          (version: n/a)
raylib.__private__  (version: 0.4.0-12-gf4f7e52)
raylib.__private__.raylib_c (version: 0.4.0)
raylib.__private__.raylib_functions (version: 0.4.0)
raylib.__private__.raylib_generated_constants (version: 0.4.0)
raylib.__private__.raylib_generated_types (version: 0.4.0)
raylib.__private__.raylib_math (version: 0.4.0)
[22:04] ~/Code/fun/ocaml/raylib $ ocamlbuild -pkg raylib raylib.ml
ocamlfind: Package `raylib_c' not found - required by `raylib'
Cannot run Ocamlfind.

setting raylib flags

I am quite new to ocaml and its build system but how does one set options like linux-display-backend to wayland

No audio on Mac OS

There is no audio playback on Mac OS (Intel and M1). There seems to be an issue with missing the CoreAudio framework in the raylib build which results in this output when calling init_audio_device

INFO: AUDIO: Device initialized successfully
INFO:     > Backend:       miniaudio / Null
INFO:     > Format:        32-bit IEEE Floating Point -> 32-bit IEEE Floating Point
INFO:     > Channels:      2 -> 2
INFO:     > Sample rate:   48000 -> 48000
INFO:     > Periods size:  1440

I tried to update the package to raylib 5.0 which seems to solve the issue. And now the audio examples are playing music and showing the CoreAudio backend in the log:

INFO: AUDIO: Device initialized successfully
INFO:     > Backend:       miniaudio / Core Audio
INFO:     > Format:        32-bit IEEE Floating Point -> 32-bit IEEE Floating Point
INFO:     > Channels:      2 -> 2
INFO:     > Sample rate:   48000 -> 48000
INFO:     > Periods size:  1440

Here are the changes I made to get the example to work:
raylib-5.0-macos-hack.patch

Creating image from memory

I want to load an image from memory, but I cannot find a function to create an image.

Equivalent in C:

Image img                          = {0};
img.format                         = PIXELFORMAT_UNCOMPRESSED_R8G8B8;
img.mipmaps                        = 1;
img.width  =1920;
img.height = 1080;
img.data   = malloc(img.width * img.height * 3);

[Bug] get_char_pressed wrong return type

The function get_char_pressed in src/c/functions/raylib_functions.ml returns the Key.t type instead of an unicode char.

GetKeyPressed returns a keycode (correct)
GetCharPressed returns an unicode char (wrong in the ocaml code)

int GetKeyPressed(void);
// Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty
int GetCharPressed(void);
// Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty
let get_key_pressed = foreign "GetKeyPressed" (void @-> returning Key.t)
let get_char_pressed = foreign "GetCharPressed" (void @-> returning Key.t)

[Feature request] Purely functional setters for Raylib structures

While implementing examples in PR #3 I end up doing a lot of creation of fresh Raylib objects, notably vectors and camera.
I was wondering if it would be possible to add purely functional setters that would be a bit more efficient in returning a new object with some parameters changes, maybe by using the copy-on-write facilities from OCaml ?

I am not seasoned enough in OCaml to tell whether such a thing is possible but I think it would be great because right now, I am pretty sure the compiler cannot tell that the new camera I am allocating should replace the old one.

Bindings for Raymath functions

Related to #3 I quickly stumbled into a problem.
I wanted to implement core_2d_camera_platformer but the C version uses Vector2* functions from Raymath and I think it is the best way to do it.
In my opinion it would be nice to add those functions inside the Raylib.Vector2 module (and do something similar for the rest of Raymath) so that we would have the possibility to call Vector2.length for example.

What do you think ?

I can do it eventually but I never made C binding myself so I don't know the tools, or even where to starts.

JPG Support

When trying to load a texture which is a JPG image I get the following error:

INFO: FILEIO: [resources/***.jpg] File loaded successfully
WARNING: IMAGE: Data format not supported
WARNING: IMAGE: Failed to load image data

Apparently this has to be explicitly enabled when building the lib?

deltaphc/raylib-rs#169

Compile program with resources?

Hi there.

Thanks for these cool bindings. I'm finding them useful and am having fun using them.

I have a question about the copying over of assets when running dune build example in your repository. When I try building the examples in your repository, the resources folder get copied into the _build directory with the compiled programs.

I tried making something with these bindings and wanted my application to use some assets (fonts) but the resources didn't get copied over when I tried compiling my application, and Google didn't give much help either so I was wondering if you could offer advice.

Thanks in advance.

unable to build raylib 0.5.1

Hi, I've tried to build the latest version of raylib-ocaml from opam (with opam install raylib) but gave me this error:

[ERROR] The compilation of raylib.0.5.1 failed at "dune build -p raylib -j 7 @install".

#=== ERROR while compiling raylib.0.5.1 =======================================#
# context     2.1.2 | linux/x86_64 | ocaml.4.13.1 | https://opam.ocaml.org#08cbb825
# path        ~/.opam/default/.opam-switch/build/raylib.0.5.1
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -p raylib -j 7 @install
# exit-code   1
# env-file    ~/.opam/log/raylib-77462-4dbee7.env
# output-file ~/.opam/log/raylib-77462-4dbee7.out
### output ###
# [...]
# 'libraylib.so' -> 'libraylib.so.400'
# make: Leaving directory '/home/ronaldo/.opam/default/.opam-switch/build/raylib.0.5.1/_build/default/src/c/vendor/raylib/src'
# (cd _build/default && /home/ronaldo/.opam/default/bin/ppx_cstubs src/c/constants/raylib_constants.ml -o src/c/constants/raylib_generated_constants.ml -I ./src/c/vendor/raylib/src)
# File "src/c/constants/raylib_constants.ml", line 5, characters 4-43:
# 5 |     | Vsync_hint [@cname "FLAG_VSYNC_HINT"]
#         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# Error: constant extraction failed for unknown reasons
# (cd _build/default && /home/ronaldo/.opam/default/bin/ppx_cstubs src/c/types/raylib_types.ml -o src/c/types/raylib_generated_types.ml -I ./src/c/vendor/raylib/src)
# /opam-tmp/build_b735f4_dune/ppxc_extract_raylib_types_d02494.c: In function ‘ppxc2_raylib_types_8e_af9_structMesh’:
# /opam-tmp/build_b735f4_dune/ppxc_extract_raylib_types_d02494.c:4529:21: warning: comparison of distinct pointer types lacks a cast
#  4529 |   (void) (&ppx__var == &ppxc_raylib_types_8e_af9_boneIds); /* field boneIds in struct Mesh incompatible? */
#       |                     ^~

Access to Mesh fields.

Is it possible to add bindings to access Mesh fields which is useful for mesh generation like here?
I've seen such bindings in old version of raylib-ocaml (0.2.0 I think), but it seems to be gone now for some reason.

Installation with opam failed

Hi,
I am having trouble installing the library. I ran opam depext raylib with opam v2.1.3. I made sure to install the dependencies with sudo pacman -S alsa-lib mesa libx11 libxrandr libxi libxcursor libxinerama and opam depext raylib. I am on manjaro 21.3.

Here is the output, that I got :

The following actions will be performed:
  ∗ install raylib 0.5.1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
⬇ retrieved raylib.0.5.1  (cached)
[ERROR] The compilation of raylib.0.5.1 failed at "dune build -p raylib -j 11 @install".

#=== ERROR while compiling raylib.0.5.1 =======================================#
# context     2.1.3 | linux/x86_64 | ocaml.4.14.0 | https://opam.ocaml.org#3a8f24e3
# path        ~/.opam/default/.opam-switch/build/raylib.0.5.1
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -p raylib -j 11 @install
# exit-code   1
# env-file    ~/.opam/log/raylib-28379-691629.env
# output-file ~/.opam/log/raylib-28379-691629.out
### output ###
# ./src/c/vendor/raylib/src/raylib.h:1027:13: warning: "callback" is deprecated: use "caml_callback" instead
# [...]
#       |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ./src/c/vendor/raylib/src/raylib.h:1028:13: warning: "callback" is deprecated: use "caml_callback" instead
#  1028 | RLAPI void SetLoadFileTextCallback(LoadFileTextCallback callback); // Set custom file text data loader
#       |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ./src/c/vendor/raylib/src/raylib.h:1029:13: warning: "callback" is deprecated: use "caml_callback" instead
#  1029 | RLAPI void SetSaveFileTextCallback(SaveFileTextCallback callback); // Set custom file text data saver
#       |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# /opam-tmp/build_3a68e9_dune/ppxc_extract_raylib_types_971446.c: In function ‘ppxc2_raylib_types_8e_af9_structMesh’:
# /opam-tmp/build_3a68e9_dune/ppxc_extract_raylib_types_971446.c:4529:21: warning: comparison of distinct pointer types lacks a cast
#  4529 |   (void) (&ppx__var == &ppxc_raylib_types_8e_af9_boneIds); /* field boneIds in struct Mesh incompatible? */
#       |                     ^~



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build raylib 0.5.1
└─ 
╶─ No changes have been performed

It would be really helpful for me to know what went wrong and how to fix the issue.

WASM support

I was wondering whether you think it's possible to export raylib-ocaml games to WASM?

`Raylib.Rlgl.set_uniform_matrix` matrix argument `Raylib__.Raylib_types.Matrix.t` seems incompatible to `Raylib.Matrix.t`.

Passing second argument for Raylib.Rlgl.set_uniform_matrix of a type Raylib.Matrix.t results in a type error:

Error: This expression has type
         Raylib.Matrix.t = Raylib.Matrix.t' Raylib.ctyp
       but an expression was expected of type
         Raylib__.Raylib_types.Matrix.t =
           (Raylib_fixed_types.Matrix.t, [ `Struct ])
           Ctypes_static.structured

Creating the same matrix with Raylib__.Raylib_types.Matrix.create helps but I have a suspicion that it's a not expected behaviour. Did I miss something?

raylib-ocaml is of version 1.1.0.

`Raylib.get_char_pressed` has wrong type

As far as I understand Raylib.get_char_pressed should have type unit -> int(or unit -> Uchar.t) instead of unit -> Raylib.Key.t since it returns unicode code point.

raygui bindings broken

The raygui bindings seems either unmaintained or just broken:

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
⬇ retrieved raygui.0.6.0  (https://opam.ocaml.org/cache)
[ERROR] The compilation of raygui.0.6.0 failed at "dune build -p raygui -j 11 @install".

#=== ERROR while compiling raygui.0.6.0 =======================================#
# context     2.1.5 | linux/x86_64 | ocaml.5.1.1 | https://opam.ocaml.org#ec28f29e
# path        ~/.opam/default/.opam-switch/build/raygui.0.6.0
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -p raygui -j 11 @install
# exit-code   1
# env-file    ~/.opam/log/raygui-40827-7d9e2c.env
# output-file ~/.opam/log/raygui-40827-7d9e2c.out
### output ###
# 164 |   (names c_generated_gui)
# [...]
# (cd _build/default/src/c && /usr/bin/gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -D_FILE_OFFSET_BITS=64 -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -I /home/<redacted>/.opam/default/lib/ocaml -I /home/<redacted>/.opam/default/lib/bigarray-compat -I /home/<redacted>/.opam/default/lib/ctypes -I /home/<redacted>/.opam/default/lib/ctypes/stubs -I /home/benja[...]
# c_generated_gui.c: In function ‘raygui_stub_37_GuiListViewEx’:
# c_generated_gui.c:378:35: error: passing argument 2 of ‘GuiListViewEx’ from incompatible pointer type [-Wincompatible-pointer-types]
#   378 |    int x405 = GuiListViewEx(x395, x396, x397, x400, x401, x402);
#       |                                   ^~~~
#       |                                   |
#       |                                   char **
# In file included from c_generated_gui.c:3:
# vendor/raygui/src/raygui.h:2724:50: note: expected ‘const char **’ but argument is of type ‘char **’
#  2724 | int GuiListViewEx(Rectangle bounds, const char **text, int count, int *focus, int *scrollIndex, int active)
#       |                                     ~~~~~~~~~~~~~^~~~



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build raygui 0.6.0
└─ 
╶─ No changes have been performed

Unbound value Seq.of_list

Hi,

which OCaml version are you using to build? I'm using 4.09.1 and I got the following compilation error.

File "src/util/raylib_gen.ml", line 134, characters 7-18:
134 |       (Seq.of_list
             ^^^^^^^^^^^
Error: Unbound value Seq.of_list

By looking at the Seq documentation from the OCaml Stdlib, looks like that function does not exists. I guess that it is taken from other library?

dune utop fails in cloned git repo and merlin does not know raylib types

not sure if this is a bug or user error.

to expore raylib-ocaml, i cloned the repo, then updated the raylib submodule by git submodule --update remote. i then descend into examples/shaders and open one of them in my editor (vim). merlin shows types for the imported Ctypes functions but not for the raylib types. after dune build from the examples directory or from the project root, nothing changes, also --profile=release does not change the lack of typing info.

i also tried launching utop by dune utop in the examples/shaders directory. this aborts with a bunch of c compiler warnings.

what am i missing?

macos.

Some unsigned int fields missing for audio-related types

Hi, first and foremost, thanks for writing these bindings! I noticed that some of the fields typed with unsigned int for audio-related types such as AudioStream and others is missing. I'd like to be able to use these in an application that I'm writing, what would be needed to be done to add support for this? I can whiff up a PR to help as well.

I'm thinking of adding a dependency to ocaml-integers to use its unsiged int type, and this shouldn't be too drastic as its already a transitive dependency from ctypes.

For reference:

typedef struct AudioStream {
    rAudioBuffer *buffer;

    unsigned int sampleRate;
    unsigned int sampleSize;
    unsigned int channels;
} AudioStream;

typedef struct Sound {
    AudioStream stream;
    unsigned int frameCount;
} Sound;

typedef struct Music {
    AudioStream stream;
    unsigned int frameCount;
    bool looping;

    int ctxType;
    void *ctxData;
} Music;

[Bug] Wrong type for some Key related functions

Some functions declared in raylib/src/camera.h are declared to take an int parameter in OCaml while they should take a Raylib_generated_constants.Key.t parameter just like is_key_down and friends.
Functions I spotted are the following:

void SetCameraPanControl(int panKey);                       // Set camera pan key to combine with mouse movement (free camera)
void SetCameraAltControl(int altKey);                       // Set camera alt key to combine with mouse movement (free camera)
void SetCameraSmoothZoomControl(int szoomKey);              // Set camera smooth zoom key to combine with mouse (free camera)
void SetCameraMoveControls(int frontKey, int backKey,
                           int rightKey, int leftKey,
                           int upKey, int downKey);         // Set camera move controls (1st person and 3rd person cameras)

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.