summaryrefslogtreecommitdiff
path: root/examples/bmp.rs
blob: 39e83e242cd91292cca7939a5221818b1a92d66a (plain)
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use std::num::NonZeroU32;

use alligator_render::{ImageFormat, Instance, RenderWindowConfig, Renderer};
use winit::event_loop::EventLoop;

fn main() {
	// configure the render window
	let config = RenderWindowConfig {
		title: "A Bumper Sticker and an Icon for Hire",
		instance_capacity: 2,
		default_width: NonZeroU32::new(1280).unwrap(),
		default_height: NonZeroU32::new(720).unwrap(),
		mode: alligator_render::config::WindowMode::BorderlessFullscreen,
		vsync: false,
		..Default::default()
	};

	let event_loop = EventLoop::new();
	let mut renderer = Renderer::new(&config, &event_loop).unwrap();

	// render the alligator
	let gator = include_bytes!("res/gator.ff");
	let gator_id = renderer
		.textures_mut()
		.load_from_memory(gator, ImageFormat::Farbfeld)
		.unwrap();
	let gator_width = renderer.textures().texture_width(gator_id).unwrap();
	let gator_height = renderer.textures().texture_height(gator_id).unwrap();
	let gator_x = renderer.textures().texture_x(gator_id).unwrap();
	let gator_y = renderer.textures().texture_y(gator_id).unwrap();

	renderer.instances_mut().push_instance(Instance {
		position: [-0.5, 0.5],
		size: [0.75; 2],
		texture_size: [gator_width, gator_height],
		texture_coordinates: [gator_x, gator_y],
		..Default::default()
	});

	// render the ghost
	let icon = include_bytes!("res/ghost.ico");
	let icon_id = renderer
		.textures_mut()
		.load_from_memory(icon, ImageFormat::Ico)
		.unwrap();
	let icon_width = renderer.textures().texture_width(icon_id).unwrap();
	let icon_height = renderer.textures().texture_height(icon_id).unwrap();
	let icon_x = renderer.textures().texture_x(icon_id).unwrap();
	let icon_y = renderer.textures().texture_y(icon_id).unwrap();

	// TODO we can make a helper function that makes a square to fit a texture
	renderer.instances_mut().push_instance(Instance {
		position: [0.5, 0.5],
		size: [0.75; 2],
		rotation: 0.5,
		texture_size: [icon_width, icon_height],
		texture_coordinates: [icon_x, icon_y],
		..Default::default()
	});

	// render the bitmap alligator
	let gator = include_bytes!("res/gator.bmp");
	let gator_id = renderer
		.textures_mut()
		.load_from_memory(gator, ImageFormat::Bmp)
		.unwrap();
	let gator_width = renderer.textures().texture_width(gator_id).unwrap();
	let gator_height = renderer.textures().texture_height(gator_id).unwrap();
	let gator_x = renderer.textures().texture_x(gator_id).unwrap();
	let gator_y = renderer.textures().texture_y(gator_id).unwrap();

	renderer.instances_mut().push_instance(Instance {
		position: [0.0, -0.5],
		size: [1.5; 2],
		texture_size: [gator_width, gator_height],
		texture_coordinates: [gator_x, gator_y],
		..Default::default()
	});

	renderer.run(event_loop);
}