#bindings #cross-platform #lean #applications #point #entry

sokol

Native bindings to the sokol header-only, cross-platform C libraries

3 releases (breaking)

Uses old Rust 2015

0.3.0 Apr 29, 2019
0.2.0 Nov 17, 2018
0.1.0 Nov 15, 2018

#997 in Audio


Used in kit

Zlib license

220KB
2K SLoC

sokol-rs

Crates.io Docs.rs zlib

Rust bindings to the sokol header-only, cross-platform libraries.

This crate provides access to sokol_gfx (3D-API wrapper), sokol_app (application framework wrapper), sokol_time (time measurement) and sokol_audio (buffer-streaming audio playback). It can serve as an easy-to-use, lean, almost dependency-free entry point to create a graphics or game application.


lib.rs:

Native bindings to the sokol header-only, cross-platform C libraries.

Example

This is a minimal example of using sokol::app and sokol::gfx to create a window, then clear its content each frame with a solid color.

use sokol::{
app::*,
gfx::*,
};

struct ExampleApp {
pass_action: SgPassAction,
}

impl SApp for ExampleApp {
fn sapp_init(&mut self) {
sg_setup(&SgDesc {
..Default::default()
});
}

fn sapp_frame(&mut self) {
sg_begin_default_pass(&self.pass_action, sapp_width(), sapp_height());
sg_end_pass();
sg_commit();
}

fn sapp_cleanup(&mut self) {
sg_shutdown();
}

fn sapp_event(&mut self, _event: SAppEvent) {
// Ignore events
}
}

fn main() {
let app = ExampleApp {
pass_action: SgPassAction {
colors: vec!(
SgColorAttachmentAction {
action: SgAction::Clear,
val: [0.5, 0.0, 0.25, 1.0],
}
),
..Default::default()
}
};

sapp_run(app, SAppDesc {
window_title: "Example".to_string(),
..Default::default()
});
}

Dependencies