messing around with imgui
parent
f2bb21e569
commit
452d1cb1ea
67
src/main.rs
67
src/main.rs
|
@ -8,7 +8,10 @@ const SCR_WIDTH: u32 = 1600;
|
||||||
const SCR_HEIGHT: u32 = 900;
|
const SCR_HEIGHT: u32 = 900;
|
||||||
const TITLE: &str = "GLFWtest";
|
const TITLE: &str = "GLFWtest";
|
||||||
|
|
||||||
|
enum gameState {
|
||||||
|
Paused,
|
||||||
|
Playing
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
use imgui_glow_renderer::AutoRenderer;
|
use imgui_glow_renderer::AutoRenderer;
|
||||||
|
@ -59,6 +62,7 @@ fn main() {
|
||||||
Ok(ret) => ret,
|
Ok(ret) => ret,
|
||||||
Err(s) => panic!("Error with Initializing SDL Context: {}", s)
|
Err(s) => panic!("Error with Initializing SDL Context: {}", s)
|
||||||
};
|
};
|
||||||
|
|
||||||
let gl = std::sync::Arc::new(unsafe{glow::Context::from_loader_function(|s| video.gl_get_proc_address(s) as *const _)});
|
let gl = std::sync::Arc::new(unsafe{glow::Context::from_loader_function(|s| video.gl_get_proc_address(s) as *const _)});
|
||||||
|
|
||||||
let event_loop = match sdl.event_pump()
|
let event_loop = match sdl.event_pump()
|
||||||
|
@ -113,13 +117,29 @@ fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let mut State = gameState::Playing;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let time = std::time::Instant::now();
|
let time = std::time::Instant::now();
|
||||||
let mut spinSpeed = 1.0;
|
let mut spinSpeed = 1.0;
|
||||||
let mut current_rad = 1.0;
|
let mut current_rad = 1.0;
|
||||||
let projection: Matrix4<f32> = perspective(Deg(45.0), SCR_WIDTH as f32/ SCR_HEIGHT as f32, 0.1, 100.0);
|
let projection: Matrix4<f32> = perspective(Deg(45.0), SCR_WIDTH as f32/ SCR_HEIGHT as f32, 0.1, 100.0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
println!("entering main loop");
|
println!("entering main loop");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// NOTE main loop here
|
// NOTE main loop here
|
||||||
'running: loop {
|
|
||||||
|
'main: loop {
|
||||||
|
match &State {
|
||||||
|
gameState::Playing => {
|
||||||
let currentFrame = time.elapsed().as_secs_f32();
|
let currentFrame = time.elapsed().as_secs_f32();
|
||||||
deltaTime = currentFrame - lastFrame;
|
deltaTime = currentFrame - lastFrame;
|
||||||
lastFrame = currentFrame;
|
lastFrame = currentFrame;
|
||||||
|
@ -160,8 +180,10 @@ fn main() {
|
||||||
ui.slider("The Spin Speed", 0.1, 10.0, &mut spinSpeed);
|
ui.slider("The Spin Speed", 0.1, 10.0, &mut spinSpeed);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
drawDebugUI(ui, &ourModel);
|
||||||
let draw_data = imgui.render();
|
let draw_data = imgui.render();
|
||||||
|
|
||||||
|
|
||||||
renderer.render(draw_data).unwrap();
|
renderer.render(draw_data).unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
@ -173,10 +195,49 @@ fn main() {
|
||||||
match event {
|
match event {
|
||||||
Event::Quit {..} |
|
Event::Quit {..} |
|
||||||
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
|
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
|
||||||
break 'running
|
break 'main
|
||||||
},
|
},
|
||||||
|
Event::KeyDown {keycode: Some(Keycode::P), ..} => {
|
||||||
|
State = gameState::Paused;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gameState::Paused => {
|
||||||
|
|
||||||
|
for event in events_loop.poll_iter() {
|
||||||
|
platform.handle_event(&mut imgui, &event);
|
||||||
|
|
||||||
|
match event {
|
||||||
|
Event::KeyDown {keycode: Some(Keycode::P), ..} => {
|
||||||
|
State = gameState::Playing;
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn drawDebugUI(ui: &imgui::Ui, model: &model::Model) {
|
||||||
|
ui.window("Stats")
|
||||||
|
.size([300.0,500.0], imgui::Condition::Always)
|
||||||
|
.build(|| {
|
||||||
|
ui.text("Model Information");
|
||||||
|
ui.separator();
|
||||||
|
ui.text(format!("count meshes: {}", model.meshes.len()));
|
||||||
|
for i in 0..model.meshes.len()
|
||||||
|
{
|
||||||
|
ui.text(format!("Mesh Number: {}",i ));
|
||||||
|
ui.text(format!("count vertices: {}", model.meshes[i].vertices.len()));
|
||||||
|
ui.separator();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue