vox/src/main.rs

100 lines
2.3 KiB
Rust

pub mod chunk;
pub mod coordinates;
pub mod platform;
pub mod voxel;
use bgfx::*;
use bgfx_rs::bgfx;
use glfw::{Action, Key, Window};
use platform::{get_platform_data, get_render_type};
const WIDTH: usize = 1280;
const HEIGHT: usize = 720;
fn main() {
let hex_coord_1 = coordinates::Hex {
q: 0.0,
r: 0.0,
s: 0.0,
y: 0.0,
};
let hex_coord_2 = coordinates::Hex {
q: 1.0,
r: 1.0,
s: 1.1,
y: 0.0,
};
hex_coord_2.round();
println!("{}", hex_coord_1.distance_to(hex_coord_2));
let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
glfw.window_hint(glfw::WindowHint::ClientApi(glfw::ClientApiHint::NoApi));
let (mut window, events) = glfw
.create_window(
WIDTH as _,
HEIGHT as _,
"Vox - ESC to close",
glfw::WindowMode::Windowed,
)
.expect("Failed to create GLFW window.");
window.set_key_polling(true);
let init = init(&window);
if !bgfx::init(&init) {
panic!("failed to init bgfx");
}
bgfx::set_view_clear(
0,
ClearFlags::COLOR.bits() | ClearFlags::DEPTH.bits(),
SetViewClearArgs {
rgba: 0x00000000,
..Default::default()
},
);
let mut old_size = (0, 0);
while !window.should_close() {
glfw.poll_events();
for (_, event) in glfw::flush_messages(&events) {
if let glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) = event {
window.set_should_close(true)
}
}
let size = window.get_framebuffer_size();
if old_size != size {
bgfx::reset(size.0 as _, size.1 as _, ResetArgs::default());
old_size = size;
}
bgfx::set_view_rect(0, 0, 0, size.0 as _, size.1 as _);
bgfx::touch(0);
bgfx::frame(false);
}
shutdown_handler();
}
pub fn shutdown_handler() {
bgfx::shutdown();
println!("shutdown");
}
pub fn init(window: &Window) -> Init {
let mut init = Init::new();
init.type_r = get_render_type();
init.resolution.width = WIDTH as u32;
init.resolution.height = HEIGHT as u32;
init.resolution.reset = ResetFlags::VSYNC.bits();
init.platform_data = get_platform_data(&window);
init
}