Dairy-Drift/src/main.rs

142 lines
3.1 KiB
Rust

use std::convert::TryInto;
//use glfw;
//use glfw::{Action, Context, Key};
use cgmath::{Matrix4, vec3, Point3, Deg, perspective};
use cgmath::prelude::*;
use std::sync::Arc;
const SCR_WIDTH: u32 = 1600;
const SCR_HEIGHT: u32 = 900;
enum gameState {
Paused,
Playing
}
enum SceneEnum {
Exit,
Resume
}
use imgui_glow_renderer::AutoRenderer;
use imgui_sdl2_support::SdlPlatform;
use glow::*;
use sdl2;
use sdl2::pixels::Color;
use sdl2::keyboard::Keycode;
use sdl2::event::Event;
use std::mem;
use std::os::raw::c_void;
use std::path::Path;
use std::ffi::{CString, CStr};
mod shader;
mod model;
mod camera;
mod scene;
mod debug;
use scene::Scene;
fn main() {
// initialize SDL and gl
let (gl, shader_version, window, mut events_loop, _context) = {
let sdl = match sdl2::init()
{
Ok(sdl) => sdl,
Err(s) => panic!("Error with Initializing SDL: {}", s),
};
let video = sdl.video().unwrap();
let gl_attr = video.gl_attr();
gl_attr.set_context_profile(sdl2::video::GLProfile::Core);
gl_attr.set_context_version(3, 3);
let window = match video
.window("DairyTest", SCR_WIDTH, SCR_HEIGHT)
.opengl()
.resizable()
.build() {
Ok(ret) => ret,
Err(s) => panic!("Error with Initializing SDL Window: {}", s),
};
let gl_context = match window.gl_create_context()
{
Ok(ret) => ret,
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 event_loop = match sdl.event_pump()
{
Ok(ret) => ret,
Err(s) => panic!("Error with Initializing SDL Event Loop: {}", s)
};
(gl, "#version 330", window, event_loop, gl_context)
};
// NOTE intiialize Camera
let mut State = gameState::Playing;
let mut scene = Scene::new(gl);
println!("entering main loop");
// NOTE main loop here
'main: loop {
match &State {
gameState::Playing => {
match scene.update(&mut events_loop, &window)
{
scene::SceneEnum::Exit => {
break 'main;
},
_ => (),
}
window.gl_swap_window();
}
gameState::Paused => {
}
}
}
}
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();
}
});
}