Created
November 27, 2022 21:55
-
-
Save hYdos/2d6b85539e0602bc0479098ef26f5fb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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