Skip to main content

Crate raylib

Crate raylib 

Source
Expand description

Safe Rust bindings to raylib 6.0.

This crate provides idiomatic Rust access to raylib’s full feature set: window management, 2D/3D drawing, input handling, raymath (vectors, matrices, quaternions), audio playback, raygui immediate-mode UI, safe rlgl OpenGL abstractions, and a headless software-renderer test harness — all without unsafe code in normal usage.

§Getting started

Call init to obtain a RaylibBuilder, configure it with chained methods, then call RaylibBuilder::build to receive a (RaylibHandle, RaylibThread) pair. Everything in the API hangs off RaylibHandle; keep it alive for the lifetime of your game loop. The RaylibThread token is !Send and !Sync — it may only be used on the thread raylib was initialised from.

§Feature gates

  • Math-crate integrations: glam, mint, serde (all opt-in, none default).
  • software_renderer — wires the rlsw memory-platform backend for windowless/headless rendering; exposes the test_harness module for pixel-probe tests. Mutually exclusive with the opengl_* features.
  • OpenGL back-end selection: opengl_33 (default), opengl_21, opengl_es_20.
  • Platform targets: drm (DRM/KMS tty, requires opengl_es_20), wayland.
  • full — convenience alias enabling all optional API surface except back-end selectors.

§Examples

The classic “Hello, world”:

use raylib::prelude::*;

let (mut rl, thread) = raylib::init()
    .size(640, 480)
    .title("Hello, World")
    .build();

while !rl.window_should_close() {
    let mut d = rl.begin_drawing(&thread);

    d.clear_background(Color::WHITE);
    d.draw_text("Hello, world!", 12, 12, 20, Color::BLACK);
}

Re-exports§

pub use crate::core::misc::open_url;
pub use crate::core::collision::*;
pub use crate::core::logging::*;
pub use crate::core::*;

Modules§

consts
Various constant enums to use with raylib
core
Safe, idiomatic wrappers over raylib’s core subsystems — window, drawing, input, audio, math, models, textures, shaders, text, files, and more.
ease
Easing and interpolation helpers.
ffi
The raw, unsafe FFI binding, in case you need that escape hatch or the safe layer doesn’t provide something you need.
prelude
Convenience re-export of the most commonly used raylib-rs items.
rlgl
Safe wrappers for rlgl, raylib’s immediate-mode OpenGL abstraction layer (rlgl.h). rlgl sits directly beneath raylib’s higher-level drawing functions and supports OpenGL 3.3, OpenGL 2.1, OpenGL ES 2.0, and the software-renderer backend — the same source compiles for all back-ends.

Macros§

rstr
Builds a NUL-terminated C string for FFI calls — &'static CStr from a string literal, or an owned CString from a format expression.

Type Aliases§

MintMatrixDeprecated
Deprecated alias for ffi::Matrix.
MintQuatDeprecated
Deprecated alias for ffi::Quaternion.
MintVec2Deprecated
Deprecated alias for ffi::Vector2; the public type is now the native raylib-sys type.
MintVec3Deprecated
Deprecated alias for ffi::Vector3.
MintVec4Deprecated
Deprecated alias for ffi::Vector4.