Initial commit

This commit is contained in:
Thibaud Gasser 2024-02-16 22:06:00 +01:00
commit 9e86f4eeb8
6 changed files with 1747 additions and 0 deletions

BIN
libraylib.a Normal file

Binary file not shown.

14
main.rs Normal file
View File

@ -0,0 +1,14 @@
mod raylib;
fn main() {
raylib::init_window(800, 600, "Hello, raylib");
while !raylib::window_should_close() {
raylib::begin_drawing();
raylib::draw_rect(0, 0, 100, 200, raylib::Color(255, 0, 0, 255));
if raylib::is_key_pressed(raylib::Key::Z) {
raylib::draw_rect(200, 200, 100, 100, raylib::Color(0, 255, 0, 0));
}
raylib::end_drawing();
}
}

1662
raylib.h Normal file

File diff suppressed because it is too large Load Diff

54
raylib.rs Normal file
View File

@ -0,0 +1,54 @@
use std::ffi::{c_char,CString};
#[repr(C)]
pub struct Color(pub u8, pub u8, pub u8, pub u8);
#[link(name = "raylib")]
extern {
fn InitWindow(width: u32, height: u32, title: *const c_char);
fn WindowShouldClose() -> bool;
fn BeginDrawing();
fn EndDrawing();
fn DrawRectangle(pos_x: u32, pos_y: u32, width: u32, height: u32, color: Color);
fn IsKeyPressed(key: u32) -> bool;
}
#[derive(Copy, Clone)]
pub enum Key {
Z = 89,
}
pub fn init_window(width: u32, height: u32, title: &str) {
unsafe {
let title = CString::new(title).unwrap();
InitWindow(width, height, title.as_ptr());
}
}
pub fn window_should_close() -> bool {
unsafe { WindowShouldClose() }
}
pub fn begin_drawing() {
unsafe { BeginDrawing(); }
}
pub fn end_drawing() {
unsafe { EndDrawing(); }
}
pub fn draw_rect(pos_x: u32, pos_y: u32, width:u32, height: u32, color: Color) {
unsafe { DrawRectangle(pos_x, pos_y, width, height, color); }
}
pub fn is_key_pressed(key: Key) -> bool {
let key = key as u32;
unsafe {
let ret = IsKeyPressed(key);
if ret {
println!("is_key_pressed({key})");
}
ret
}
}

16
raylib_LICENSE Normal file
View File

@ -0,0 +1,16 @@
Copyright (c) 2013-2023 Ramon Santamaria (@raysan5)
This 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.
Permission 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:
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.
2. Altered source versions must be plainly marked as such, and must not be misrepresented
as being the original software.
3. This notice may not be removed or altered from any source distribution.

1
readme Normal file
View File

@ -0,0 +1 @@
rustc -L. -lraylib test.rs && ./test