-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from ian-h-chamberlain/example/graphics-bitmap
- Loading branch information
Showing
4 changed files
with
110 additions
and
16 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use ctru::console::Console; | ||
use ctru::gfx::Screen as _; | ||
use ctru::services::hid::KeyPad; | ||
use ctru::services::{Apt, Hid}; | ||
use ctru::Gfx; | ||
|
||
/// Ferris image taken from <https://rustacean.net> and scaled down to 320x240px. | ||
/// To regenerate the data, you will need to install `imagemagick` and run this | ||
/// command from the `examples` directory: | ||
/// | ||
/// ```sh | ||
/// magick assets/ferris.png -channel-fx "red<=>blue" -rotate 90 assets/ferris.rgb | ||
/// ``` | ||
/// | ||
/// This creates an image appropriate for the default frame buffer format of | ||
/// [`Bgr8`](ctru::services::gspgpu::FramebufferFormat::Bgr8) | ||
/// and rotates the image 90° to account for the portrait mode screen. | ||
static IMAGE: &[u8] = include_bytes!("assets/ferris.rgb"); | ||
|
||
fn main() { | ||
ctru::init(); | ||
let gfx = Gfx::default(); | ||
let hid = Hid::init().expect("Couldn't obtain HID controller"); | ||
let apt = Apt::init().expect("Couldn't obtain APT controller"); | ||
let _console = Console::init(gfx.top_screen.borrow_mut()); | ||
|
||
println!("\x1b[21;16HPress Start to exit."); | ||
|
||
let mut bottom_screen = gfx.bottom_screen.borrow_mut(); | ||
|
||
// We don't need double buffering in this example. | ||
// In this way we can draw our image only once on screen. | ||
bottom_screen.set_double_buffering(false); | ||
|
||
// We assume the image is the correct size already, so we drop width + height. | ||
let frame_buffer = bottom_screen.get_raw_framebuffer(); | ||
|
||
// Copy the image into the frame buffer | ||
unsafe { | ||
frame_buffer.ptr.copy_from(IMAGE.as_ptr(), IMAGE.len()); | ||
} | ||
|
||
// Main loop | ||
while apt.main_loop() { | ||
//Scan all the inputs. This should be done once for each frame | ||
hid.scan_input(); | ||
|
||
if hid.keys_down().contains(KeyPad::KEY_START) { | ||
break; | ||
} | ||
|
||
// Flush and swap framebuffers | ||
gfx.flush_buffers(); | ||
gfx.swap_buffers(); | ||
|
||
//Wait for VBlank | ||
gfx.wait_for_vblank(); | ||
} | ||
} |
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