added debug.rs and moved some code there
parent
a3eb4017cf
commit
f4b4295df1
|
@ -0,0 +1,85 @@
|
||||||
|
|
||||||
|
use imgui_glow_renderer::AutoRenderer;
|
||||||
|
use imgui_sdl2_support::SdlPlatform;
|
||||||
|
|
||||||
|
use sdl2::event::Event;
|
||||||
|
const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/models/TestCarModel/CarW1.obj",
|
||||||
|
"resources/models/TestCarModel/CarW0.obj"];
|
||||||
|
|
||||||
|
|
||||||
|
pub struct Debug {
|
||||||
|
imgui: imgui::Context,
|
||||||
|
renderer: AutoRenderer,
|
||||||
|
platform: SdlPlatform,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Debug {
|
||||||
|
pub fn new(gl: std::sync::Arc<glow::Context>) -> Debug
|
||||||
|
{
|
||||||
|
let mut imgui = imgui::Context::create();
|
||||||
|
|
||||||
|
imgui
|
||||||
|
.fonts()
|
||||||
|
.add_font(&[imgui::FontSource::DefaultFontData {config: None}]);
|
||||||
|
|
||||||
|
let mut platform = SdlPlatform::init(&mut imgui);
|
||||||
|
let mut renderer = match AutoRenderer::initialize(gl.clone(), &mut imgui)
|
||||||
|
{
|
||||||
|
Ok(ret) => ret,
|
||||||
|
Err(s) => panic!("Failed to initialize Imgui Platform Renderer: {}", s),
|
||||||
|
};
|
||||||
|
Debug {
|
||||||
|
imgui,
|
||||||
|
renderer,
|
||||||
|
platform
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handle(&mut self, event: &sdl2::event::Event)
|
||||||
|
{
|
||||||
|
self.platform.handle_event(&mut self.imgui, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn drawImgui(&mut self, events_loop: &sdl2::EventPump, window: &sdl2::video::Window,
|
||||||
|
tempData: &mut crate::scene::tempData, Car: &crate::model::Model)
|
||||||
|
{
|
||||||
|
self.platform.prepare_frame(&mut self.imgui, &window, &events_loop );
|
||||||
|
let ui = self.imgui.new_frame();
|
||||||
|
let mut hello = String::new();
|
||||||
|
|
||||||
|
ui.window("POLY I WILL FUCKING")
|
||||||
|
.size([500.0, 100.0], imgui::Condition::FirstUseEver)
|
||||||
|
.build(|| {
|
||||||
|
ui.text("you serve no purpose in life");
|
||||||
|
ui.text("Your Purpose in life is to suck my dick");
|
||||||
|
ui.slider("The Spin Speed", 0.1, 10.0, &mut tempData.spinSpeed);
|
||||||
|
if ui
|
||||||
|
.button("Quit") {
|
||||||
|
hello = String::from("cannot quit from here");
|
||||||
|
|
||||||
|
}
|
||||||
|
ui.text(hello);
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.window("Stats")
|
||||||
|
.size([300.0,500.0], imgui::Condition::Always)
|
||||||
|
.build(|| {
|
||||||
|
ui.text("Model Information");
|
||||||
|
ui.separator();
|
||||||
|
ui.text(format!("count meshes: {}", Car.meshes.len()));
|
||||||
|
for i in 0..Car.meshes.len()
|
||||||
|
{
|
||||||
|
ui.text(format!("Mesh Number: {}",i ));
|
||||||
|
ui.text(format!("count vertices: {}", Car.meshes[i].vertices.len()));
|
||||||
|
ui.separator();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
let draw_data = self.imgui.render();
|
||||||
|
|
||||||
|
self.renderer.render(draw_data).unwrap();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -39,6 +39,7 @@ mod shader;
|
||||||
mod model;
|
mod model;
|
||||||
mod camera;
|
mod camera;
|
||||||
mod scene;
|
mod scene;
|
||||||
|
mod debug;
|
||||||
|
|
||||||
use scene::Scene;
|
use scene::Scene;
|
||||||
|
|
||||||
|
|
62
src/scene.rs
62
src/scene.rs
|
@ -22,7 +22,6 @@ const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/
|
||||||
"resources/models/TestCarModel/CarW0.obj"];
|
"resources/models/TestCarModel/CarW0.obj"];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// XXX this is temporary, thus the name
|
/// XXX this is temporary, thus the name
|
||||||
pub struct tempData {
|
pub struct tempData {
|
||||||
pub projection: Matrix4<f32>,
|
pub projection: Matrix4<f32>,
|
||||||
|
@ -33,6 +32,7 @@ pub struct tempData {
|
||||||
pub lastFrame: f32,
|
pub lastFrame: f32,
|
||||||
DebugMode: bool,
|
DebugMode: bool,
|
||||||
}
|
}
|
||||||
|
use crate::debug::Debug;
|
||||||
|
|
||||||
pub enum SceneEnum {
|
pub enum SceneEnum {
|
||||||
Exit,
|
Exit,
|
||||||
|
@ -45,9 +45,7 @@ pub struct Scene {
|
||||||
gl: Arc<glow::Context>,
|
gl: Arc<glow::Context>,
|
||||||
pub Car: Model,
|
pub Car: Model,
|
||||||
camera: Camera,
|
camera: Camera,
|
||||||
imgui: imgui::Context,
|
debug: Debug,
|
||||||
imgui_rend: AutoRenderer,
|
|
||||||
imgui_plat: SdlPlatform,
|
|
||||||
shaders: Vec<Rc<shader>>,
|
shaders: Vec<Rc<shader>>,
|
||||||
time: std::time::Instant,
|
time: std::time::Instant,
|
||||||
tempData: tempData,
|
tempData: tempData,
|
||||||
|
@ -79,26 +77,12 @@ impl Scene{
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut imgui = imgui::Context::create();
|
let debug = Debug::new(gl.clone());
|
||||||
|
|
||||||
imgui
|
|
||||||
.fonts()
|
|
||||||
.add_font(&[imgui::FontSource::DefaultFontData {config: None}]);
|
|
||||||
|
|
||||||
let mut platform = SdlPlatform::init(&mut imgui);
|
|
||||||
let mut renderer = match AutoRenderer::initialize(gl.clone(), &mut imgui)
|
|
||||||
{
|
|
||||||
Ok(ret) => ret,
|
|
||||||
Err(s) => panic!("Failed to initialize Imgui Platform Renderer: {}", s),
|
|
||||||
};
|
|
||||||
|
|
||||||
Scene{
|
Scene{
|
||||||
gl,
|
gl,
|
||||||
Car,
|
Car,
|
||||||
camera,
|
camera,
|
||||||
imgui,
|
debug,
|
||||||
imgui_rend: renderer,
|
|
||||||
imgui_plat: platform,
|
|
||||||
shaders: vec![shader],
|
shaders: vec![shader],
|
||||||
time,
|
time,
|
||||||
tempData,
|
tempData,
|
||||||
|
@ -131,13 +115,13 @@ impl Scene{
|
||||||
self.Car.Draw(&self.shaders[0]);
|
self.Car.Draw(&self.shaders[0]);
|
||||||
|
|
||||||
if self.tempData.DebugMode{
|
if self.tempData.DebugMode{
|
||||||
self.drawImgui(&events_loop, &window);
|
self.debug.drawImgui(&events_loop, &window, &mut self.tempData, &self.Car);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut ret = SceneEnum::Resume;
|
let mut ret = SceneEnum::Resume;
|
||||||
for event in events_loop.poll_iter() {
|
for event in events_loop.poll_iter() {
|
||||||
if self.tempData.DebugMode {
|
if self.tempData.DebugMode {
|
||||||
self.imgui_plat.handle_event(&mut self.imgui, &event);
|
self.debug.handle(&event);
|
||||||
}
|
}
|
||||||
match event {
|
match event {
|
||||||
Event::Quit {..} |
|
Event::Quit {..} |
|
||||||
|
@ -158,38 +142,4 @@ impl Scene{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn drawImgui(&mut self, events_loop: &sdl2::EventPump, window: &sdl2::video::Window)
|
|
||||||
{
|
|
||||||
self.imgui_plat.prepare_frame(&mut self.imgui, &window, &events_loop );
|
|
||||||
let ui = self.imgui.new_frame();
|
|
||||||
|
|
||||||
ui.window("POLY I WILL FUCKING")
|
|
||||||
.size([500.0, 100.0], imgui::Condition::FirstUseEver)
|
|
||||||
.build(|| {
|
|
||||||
ui.text("you serve no purpose in life");
|
|
||||||
ui.text("Your Purpose in life is to suck my dick");
|
|
||||||
ui.slider("The Spin Speed", 0.1, 10.0, &mut self.tempData.spinSpeed);
|
|
||||||
});
|
|
||||||
|
|
||||||
ui.window("Stats")
|
|
||||||
.size([300.0,500.0], imgui::Condition::Always)
|
|
||||||
.build(|| {
|
|
||||||
ui.text("Model Information");
|
|
||||||
ui.separator();
|
|
||||||
ui.text(format!("count meshes: {}", self.Car.meshes.len()));
|
|
||||||
for i in 0..self.Car.meshes.len()
|
|
||||||
{
|
|
||||||
ui.text(format!("Mesh Number: {}",i ));
|
|
||||||
ui.text(format!("count vertices: {}", self.Car.meshes[i].vertices.len()));
|
|
||||||
ui.separator();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
let draw_data = self.imgui.render();
|
|
||||||
|
|
||||||
self.imgui_rend.render(draw_data).unwrap();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue