Skip to main content

sola_raylib/
lib.rs

1/* raylib-rs
2   lib.rs - Main library code (the safe layer)
3
4Copyright (c) 2018-2024 raylib-rs team
5
6This software is provided "as-is", without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
7
8Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
9
10  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
11
12  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13
14  3. This notice may not be removed or altered from any source distribution.
15*/
16
17//! # sola-raylib
18//!
19//! `sola_raylib` is a safe Rust binding to [Raylib](https://www.raylib.com/), a C library for enjoying games programming.
20//!
21//! To get started, take a look at the [`init_window`] function. This initializes Raylib and shows a window, and returns a [`RaylibHandle`]. This handle is very important, because it is the way in which one accesses the vast majority of Raylib's functionality. This means that it must not go out of scope until the game is ready to exit. You will also recieve a !Send and !Sync [`RaylibThread`] required for thread local functions.
22//!
23//! For more control over the game window, the [`init`] function will return a [`RaylibBuilder`] which allows for tweaking various settings such as VSync, anti-aliasing, fullscreen, and so on. Calling [`RaylibBuilder::build`] will then provide a [`RaylibHandle`].
24//!
25//! Some useful constants can be found in the [`consts`] module, which is also re-exported in the [`prelude`] module. In most cases you will probably want to `use sola_raylib::prelude::*;` to make your experience more smooth.
26//!
27//! [`init_window`]: fn.init_window.html
28//! [`init`]: fn.init.html
29//! [`RaylibHandle`]: struct.RaylibHandle.html
30//! [`RaylibThread`]: struct.RaylibThread.html
31//! [`RaylibBuilder`]: struct.RaylibBuilder.html
32//! [`RaylibBuilder::build`]: struct.RaylibBuilder.html#method.build
33//! [`consts`]: consts/index.html
34//! [`prelude`]: prelude/index.html
35//!
36//! # Examples
37//!
38//! The classic "Hello, world":
39//!
40//! ```no_run
41//! use sola_raylib::prelude::*;
42//!
43//! fn main() {
44//!     let (mut rl, thread) = sola_raylib::init()
45//!         .size(640, 480)
46//!         .title("Hello, World")
47//!         .build();
48//!
49//!     while !rl.window_should_close() {
50//!         let mut d = rl.begin_drawing(&thread);
51//!
52//!         d.clear_background(Color::WHITE);
53//!         d.draw_text("Hello, world!", 12, 12, 20, Color::BLACK);
54//!     }
55//! }
56//! ```
57//!
58//! ## Building for the web
59//!
60//! sola-raylib supports `wasm32-unknown-emscripten`. The link flags
61//! raylib needs (`-sUSE_GLFW=3`, `-sASYNCIFY=1`, etc.) live in your
62//! project's `.cargo/config.toml`, since cargo can't propagate linker
63//! flags out of a sys-crate build script.
64//! [`core::game_loop::run`] is the cross-platform loop helper. The
65//! [project web guide] has the config recipe, asset bundling, save
66//! data, audio, and deploy notes.
67//!
68//! [`core::game_loop::run`]: core::game_loop::run
69//! [project web guide]: https://github.com/brettchalupa/sola-raylib/blob/main/book/src/web.md
70//!
71//! ## Cargo features
72//!
73//! `sola-raylib` exposes Cargo features that toggle build-time options on the
74//! underlying raylib C library. The full reference, with platform notes and
75//! known-broken flags, lives in the [project README]; the quick summary:
76//!
77//! **Build / linking**
78//! - `bindgen` *(default)*: generate FFI bindings at build time. Disable to
79//!   supply a hand-rolled `bindings.rs` (for platforms bindgen can't target).
80//! - `nobuild`: skip building and linking raylib entirely. You then link it
81//!   yourself (used for docs.rs and headless setups).
82//!
83//! **Platform and rendering backend**
84//! - `wayland`: build raylib's GLFW with native Wayland support on Linux.
85//!   Requires the system `glfw-devel` (cmake config files), not just the
86//!   runtime.
87//! - `sdl`: use the SDL platform backend. The build script auto-picks SDL3 if
88//!   present, otherwise SDL2, via `pkg-config`.
89//! - `opengl_33` / `opengl_21` / `opengl_es_20` / `opengl_es_30`: force a
90//!   specific GL backend.
91//! - `software_render`, `platform_memory`, `platform_web_rgfw`: experimental
92//!   raylib 6.0 backends. See the README for caveats.
93//!
94//! **Behavior toggles**
95//! - `custom_frame_control`: enable raylib's `SUPPORT_CUSTOM_FRAME_CONTROL`,
96//!   so you drive frame timing yourself.
97//! - `noscreenshot`: disable raylib's built-in F12 screenshot keybind.
98//!
99//! **Interop**
100//! - `with_serde`: derive `serde::Serialize` / `Deserialize` on public types.
101//! - `convert_mint`: conversions to/from the [`mint`](https://docs.rs/mint)
102//!   math types.
103//!
104//! [project README]: https://github.com/brettchalupa/sola-raylib#cargo-features
105
106#![allow(dead_code)]
107pub mod consts;
108pub mod core;
109pub mod ease;
110pub mod prelude;
111pub mod rgui;
112
113/// The raw, unsafe FFI binding, in case you need that escape hatch or the safe layer doesn't provide something you need.
114pub mod ffi {
115    pub use raylib_sys::*;
116}
117
118pub use crate::core::collision::*;
119pub use crate::core::misc::open_url;
120pub use crate::core::*;
121
122// Re-exports
123#[cfg(feature = "with_serde")]
124pub use serde;