raygui

OCaml bindings for raygui
README

raylib-ocaml

OCaml bindings for raylib (4.0.0), a simple and easy-to-use library to enjoy videogames programming.

The documentation can be viewed online.

The bindings are pretty faithful to the original C code, the biggest difference is the conversion of all function names from CamelCase to snake_case.
Wherever possible, integer arguments are changed to their own variant types, eg. int key to Key.t.

Bindings exist for (nearly) all functions and types, but only a subset are tested thus far (see examples folder). Rough edges are to be expected.

Example

let setup () =
  Raylib.init_window 800 450 "raylib [core] example - basic window";
  Raylib.set_target_fps 60

let rec loop () =
  match Raylib.window_should_close () with
  | true -> Raylib.close_window ()
  | false ->
      let open Raylib in
      begin_drawing ();
      clear_background Color.raywhite;
      draw_text "Congrats! You created your first window!" 190 200 20
        Color.lightgray;
      end_drawing ();
      loop ()

let () = setup () |> loop

More examples can be found in the examples folder.

Although the original raylib is written in C, most functions take their arguments by value, which maps nicely to a functional language like OCaml. In the few cases where pointers are needed for arrays (mainly the 3D part of raylib), raylib-ocaml tries to use the CArray type of ctypes, which it also re-exports in the main Raylib module.

Installation

During the build of raylib-ocaml, the raylib C library is built from source, therefore its dependencies must be installed (details here).
For some distros, depexts exist (feel free to contribute depexts for missing distros) to automatically install these dependencies:

opam depext raylib

raylib-ocaml can be installed via opam:

opam install raylib

Examples

To build the examples, make sure the raylib C submodule is available with git submodule update --init --recursive. Then simply

dune build

inside this repo. The binaries can then be found in _build/default/examples.

Raygui

In addition to raylib, there are bindings to raygui, an immediate mode gui library which complements raylib.
The documentation of the raygui bindings can be viewed online as well.
As with the raylib bindings, the bindings stick close to the C source.
An exception to this are the *_style functions, which take a polymorphic variant.
An example can be found in examples/gui.

TODO

  • Split the library into components (core, sound, 3D, VR etc) for a smaller memory footprint

Install
Published
21 Apr 2022
Sources
raygui-0.5.1.tbz
sha256=ace92b528632084ef1467e97aa14e772cdca10e8f3f26f3445473f7c1dbdba88
sha512=9aa37cd17f88f251cf9ce79dc4f8e0df61113f88f6b3a0ee05bb75b734847ce4393093df8a98b2c41103cc3e741fc75baeda8ffc5ec66b2c6f49c5576de80872
Dependencies
odoc
with-doc
raylib
>= "0.3"
ppx_cstubs
>= "0.6"
ctypes
>= "0.14"
dune
>= "2.8"
Reverse Dependencies