initial Commit

pull/4/head
Milk.H 2024-04-25 16:23:24 +01:00
commit 19eb37a455
Signed by: milk
GPG Key ID: 94C7CB70FFF80593
3 changed files with 164 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

18
Cargo.toml Normal file
View File

@ -0,0 +1,18 @@
[package]
name = "mgq-fighter"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy_ecs = "0.13.2"
cgmath = "0.18.0"
egui = "0.27.2"
egui-winit = "0.27.2"
egui_glow = { version = "0.27.2", features = ["winit"] }
glow = "0.13.1"
glutin = "0.31.3"
glutin-winit = "0.4.2"
raw-window-handle = "0.6.1"
winit = "0.29.15"

145
src/main.rs Normal file
View File

@ -0,0 +1,145 @@
use std::rc::Rc;
use std::sync::Arc;
use glow::HasContext;
use winit::{event_loop::EventLoopBuilder, window::WindowBuilder};
use winit::event::{Event, WindowEvent};
use glutin::{config::ConfigTemplateBuilder, context::ContextAttributesBuilder};
use glutin_winit::DisplayBuilder;
use glutin::{prelude::*, context::Version};
use glutin_winit::{self, GlWindow};
use glutin::display::GetGlDisplay;
fn main() {
// NOTE initialization code here
// create Event Loop
let event_loop = EventLoopBuilder::new().build().unwrap();
// set event loop to poll events every frame
event_loop.set_control_flow(winit::event_loop::ControlFlow::Poll);
let window_builder = Some(WindowBuilder::new()
.with_transparent(true)
);
let template = ConfigTemplateBuilder::new();
let display_builder = DisplayBuilder::new()
.with_window_builder(window_builder);
let (window, gl_config) = display_builder
.build(&event_loop, template, |configs| {
configs.reduce(|accum, config| {
let transparency_check = config.supports_transparency().unwrap_or(true)
& !accum.supports_transparency().unwrap_or(true);
if transparency_check || config.num_samples() > accum.num_samples() {
config
}
else {
accum
}
})
.unwrap()
})
.unwrap();
// probably not needed here
//let raw_window_handle = window.as_ref().map(|window| window.window_handle()
// .unwrap()
// .as_raw());
let gl_display = gl_config.display();
let context_attributes = ContextAttributesBuilder::new().build(None);
let fallback_attributes = ContextAttributesBuilder::new()
.with_context_api(glutin::context::ContextApi::Gles(None))
.build(None);
let compatibility_context_attributes = ContextAttributesBuilder::new()
.with_context_api(glutin::context::ContextApi::OpenGl(Some(Version::new(3, 3))))
.build(None);
// decide on the opengl Context to use, will use the newest one available
let mut not_current_gl_context = Some(unsafe {
gl_display.create_context(&gl_config, &context_attributes).unwrap_or_else(|_| {
gl_display.create_context(&gl_config, &fallback_attributes).unwrap_or_else(|_| {
gl_display
.create_context(&gl_config, &compatibility_context_attributes)
.expect("get a newer Computer")
},
)
})
});
// current Window Reference Counter
let window = Rc::new(window.unwrap());
// window title
window.set_title("MGQ Fighter Test");
let attrs = window.build_surface_attributes(<_>::default());
let gl_surface = unsafe {
gl_config.display().create_window_surface(&gl_config, &attrs).unwrap()
};
let gl_context = not_current_gl_context
.take()
.unwrap()
.make_current(&gl_surface)
.unwrap();
// the Glow context wrapped in an Atomic Reference Counter
let gl = Arc::new(unsafe {
glow::Context::from_loader_function(|s| {
let s = std::ffi::CString::new(s).unwrap();
gl_display.get_proc_address(s.as_c_str()).cast()
})
});
// TODO write bevy Init code here
let _ = event_loop.run(move |event, control_flow| {
match event
{
Event::WindowEvent { event, .. } => {
match event
{
WindowEvent::CloseRequested => {
println!("closing gracefully");
control_flow.exit();
},
// TODO to be implemented later
_ => ()
};
}
Event::AboutToWait => {
unsafe {
gl.clear_color(0.0, 0.0, 0.0, 0.0);
gl.clear(glow::COLOR_BUFFER_BIT);
}
},
// TODO to be implemented
_ => ()
}
});
}