package raylib

  1. Overview
  2. Docs
OCaml bindings for raylib

Install

Dune Dependency

Authors

Maintainers

Sources

raylib-1.2.1.tbz
sha256=982fb88c51dcc980fceee4c61e900464c186b67e030ea0be680b27a62ea4b0a5
sha512=72699357fed2c64d8530f1d4344026dcb88b22c456729fd67d4a6d9725ba008b2e69537b0fc24a6203750812576297f67ba4824c21698fce31c70eaae101abc7

Description

OCaml bindings for raylib

Published: 14 Jan 2024

README

README.md

raylib-ocaml

OCaml bindings for raylib (5.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). Contributions are welcome.

Example

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

let rec loop () =
  if Raylib.window_should_close () then Raylib.close_window ()
  else
    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

Dependencies (9)

  1. conf-libxrandr os = "linux" | os-family = "bsd"
  2. conf-libxinerama os = "linux" | os-family = "bsd"
  3. conf-libxi os = "linux" | os-family = "bsd"
  4. conf-libxcursor os = "linux" | os-family = "bsd"
  5. conf-mesa os = "linux" | os-family = "bsd"
  6. integers >= "0.5"
  7. ctypes >= "0.14"
  8. dune-configurator
  9. dune >= "2.8"

Dev Dependencies (1)

  1. odoc with-doc

Used by (1)

  1. raygui >= "0.6.0"

Conflicts

None

OCaml

Innovation. Community. Security.