tjammer / raylib-ocaml Goto Github PK
View Code? Open in Web Editor NEWOCaml bindings for raylib and raygui
Home Page: https://tjammer.github.io/raylib-ocaml/
License: MIT License
OCaml bindings for raylib and raygui
Home Page: https://tjammer.github.io/raylib-ocaml/
License: MIT License
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 🙂
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.
I am quite new to ocaml and its build system but how does one set options like linux-display-backend to wayland
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
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);
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)
Reported on discord.
We might be able to add this build to actions using an m1 runner. setup-ocaml should have support for it, according to
and
https://github.com/rescript-lang/rescript-compiler/pull/5415/files.
This would allow me to debug the issue as I don't have a m1 machine
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.
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.
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?
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.
...and support OCaml 5 ;-)
Originally posted by @ul in #27 (comment)
Hi, it seems raygui package wasn't updated on opam as it's linked to raylib 0.3.2 while raylib latest version is more recent.
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? */
# | ^~
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.
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.
I was wondering whether you think it's possible to export raylib-ocaml games to WASM?
are there plans to support raygui? It'd be useful to get a quick GUI running in OCaml…
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.
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.
I want to call draw_line_strip
which has type Raylib.Vector2.t Ctypes.ptr
, but unless I'm missing something, it's impossible to build a CArray of vector2 with the API at present.
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
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?
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.
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;
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)
New raylib version just released https://github.com/raysan5/raylib/releases/tag/4.2.0
Might be a good reason to try out the new dune ctypes stanza
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.