Compare commits

...

2 Commits

Author SHA1 Message Date
Milk.H aed0b606c2
can change models now 2023-03-21 15:14:10 +01:00
Milk.H f4b4295df1
added debug.rs and moved some code there 2023-03-21 14:14:15 +01:00
3 changed files with 119 additions and 57 deletions

100
src/debug.rs Normal file
View File

@ -0,0 +1,100 @@
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 enum dEvent
{
loadModel(i32),
exit,
}
pub struct Debug {
imgui: imgui::Context,
renderer: AutoRenderer,
platform: SdlPlatform,
selectedModel: i32
}
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,
selectedModel: 0,
}
}
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) -> Vec<dEvent>
{
self.platform.prepare_frame(&mut self.imgui, &window, &events_loop );
let ui = self.imgui.new_frame();
let mut ret = Vec::<dEvent>::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") {
ret.push(dEvent::exit);
}
if ui.list_box("Select Model to Load", &mut self.selectedModel, &MODELS, 5) {
ret.push(dEvent::loadModel(self.selectedModel));
}
});
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();
ret
}
}

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,
@ -111,6 +95,7 @@ impl Scene{
self.tempData.deltaTime = self.tempData.currentFrame - self.tempData.lastFrame;
self.tempData.lastFrame = self.tempData.currentFrame;
self.tempData.current_rad += self.tempData.spinSpeed/15.0;
let mut ret = SceneEnum::Resume;
unsafe {
self.gl.enable(glow::DEPTH_TEST);
@ -131,13 +116,23 @@ impl Scene{
self.Car.Draw(&self.shaders[0]);
if self.tempData.DebugMode{
self.drawImgui(&events_loop, &window);
for command in self.debug.drawImgui(&events_loop, &window, &mut self.tempData, &self.Car)
{
use crate::debug::dEvent;
match command
{
dEvent::exit => ret = SceneEnum::Exit,
dEvent::loadModel(i) => {
self.Car = Model::new(MODELS[i as usize], Arc::clone(&self.gl));
}
_ => (),
}
}
}
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 +153,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();
}
}