added debug.rs and moved some code there

pull/3/head
Milk.H 2023-03-21 14:14:15 +01:00
parent a3eb4017cf
commit f4b4295df1
No known key found for this signature in database
GPG Key ID: 3D9DAE46AAC37BD8
3 changed files with 92 additions and 56 deletions

85
src/debug.rs Normal file
View File

@ -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();
}
}

View File

@ -39,6 +39,7 @@ mod shader;
mod model;
mod camera;
mod scene;
mod debug;
use scene::Scene;

View File

@ -22,7 +22,6 @@ const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/
"resources/models/TestCarModel/CarW0.obj"];
/// XXX this is temporary, thus the name
pub struct tempData {
pub projection: Matrix4<f32>,
@ -33,6 +32,7 @@ pub struct tempData {
pub lastFrame: f32,
DebugMode: bool,
}
use crate::debug::Debug;
pub enum SceneEnum {
Exit,
@ -45,9 +45,7 @@ pub struct Scene {
gl: Arc<glow::Context>,
pub Car: Model,
camera: Camera,
imgui: imgui::Context,
imgui_rend: AutoRenderer,
imgui_plat: SdlPlatform,
debug: Debug,
shaders: Vec<Rc<shader>>,
time: std::time::Instant,
tempData: tempData,
@ -79,26 +77,12 @@ impl Scene{
};
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),
};
let debug = Debug::new(gl.clone());
Scene{
gl,
Car,
camera,
imgui,
imgui_rend: renderer,
imgui_plat: platform,
debug,
shaders: vec![shader],
time,
tempData,
@ -131,13 +115,13 @@ impl Scene{
self.Car.Draw(&self.shaders[0]);
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;
for event in events_loop.poll_iter() {
if self.tempData.DebugMode {
self.imgui_plat.handle_event(&mut self.imgui, &event);
self.debug.handle(&event);
}
match event {
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();
}
}