Skip to content

Instantly share code, notes, and snippets.

@hYdos
Created November 27, 2022 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hYdos/2d6b85539e0602bc0479098ef26f5fb0 to your computer and use it in GitHub Desktop.
Save hYdos/2d6b85539e0602bc0479098ef26f5fb0 to your computer and use it in GitHub Desktop.
use citro3d_sys::C3D_Tex;
use std::mem::MaybeUninit;
use ctru::prelude::KeyPad;
use ctru::services::Hid;
#[repr(C)]
pub struct Vec3 {
x: f32,
y: f32,
z: f32,
}
impl Vec3 {
pub const fn new(x: f32, y: f32, z: f32) -> Self {
Self { x, y, z }
}
}
#[repr(C)]
pub struct Vec2 {
x: f32,
y: f32,
}
impl Vec2 {
pub const fn new(x: f32, y: f32) -> Self {
Self { x, y }
}
}
pub unsafe fn load_texture_from_mem(path: &str) -> C3D_Tex {
let rom_path = format!("romfs:/{path}");
let bytes = std::fs::read(&rom_path).unwrap_or_else(|_| panic!("Failed to read {rom_path}"));
load_texture_from_bytes(&bytes)
}
pub unsafe fn load_texture_from_bytes(bytes: &[u8]) -> C3D_Tex {
let mut _tex = MaybeUninit::uninit();
let t3x = citro3d_sys::Tex3DS_TextureImport(
bytemuck::cast_slice::<u8, u32>(bytes).as_ptr() as *const _,
bytes.len(),
_tex.as_mut_ptr(),
std::ptr::null_mut(),
false,
);
let tex = _tex.assume_init();
// Delete the t3x object since we don't need it
citro3d_sys::Tex3DS_TextureFree(t3x);
tex
}
pub fn wait(hid: &Hid) {
println!("Paused. Press Start to continue.");
loop {
hid.scan_input();
// Continue key
if hid.keys_held().contains(KeyPad::KEY_START) {
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment