aspen_engine/lib.rs
1pub mod application;
2pub mod interface;
3pub mod renderer;
4pub mod timing;
5
6/*
7use glutin::{config::{Config, ConfigTemplateBuilder}, context::ContextAttributesBuilder, display::GetGlDisplay};
8use glutin_winit::{DisplayBuilder, GlWindow};
9use glutin::prelude::*;
10use winit::{event::{Event, KeyEvent, WindowEvent}, event_loop::EventLoop, keyboard::{Key, NamedKey}, window::WindowBuilder};
11use raw_window_handle::HasRawWindowHandle;
12
13fn main() {
14 let event_loop = EventLoop::new().expect("failed to create event loop");
15 let window_builder = WindowBuilder::new()
16 .with_title("cool window");
17
18 let template = ConfigTemplateBuilder::new().with_alpha_size(8).with_transparency(cfg!(cgl_backend));
19
20 let display_builder = DisplayBuilder::new().with_window_builder(Some(window_builder));
21
22 let (window, gl_config) = display_builder.build(&event_loop, template, gl_config_picker).unwrap();
23 let raw_window_handle = window.as_ref().map(|window| window.raw_window_handle());
24
25 let gl_display = gl_config.display();
26
27 let context_attributes = ContextAttributesBuilder::new().build(raw_window_handle);
28
29 let mut not_current_gl_context = Some(unsafe {
30 gl_display.create_context(&gl_config, &context_attributes).expect("failed to create gl context")
31 });
32
33 let mut window = window.unwrap();
34
35 let attrs = window.build_surface_attributes(Default::default());
36 let gl_surface = unsafe {
37 gl_config.display().create_window_surface(&gl_config, &attrs).unwrap()
38 };
39
40 let gl_context = not_current_gl_context.take().unwrap().make_current(&gl_surface).unwrap();
41
42 event_loop.run(move |event, window_target| {
43 match event {
44 Event::WindowEvent { event, .. } => match event {
45 WindowEvent::Resized(size) => {
46 if size.width != 0 && size.height != 0 {
47 // Some platforms like EGL require resizing GL surface to update the size
48 // Notable platforms here are Wayland and macOS, other don't require it
49 // and the function is no-op, but it's wise to resize it for portability
50 // reasons.
51 }
52 },
53 WindowEvent::CloseRequested
54 | WindowEvent::KeyboardInput {
55 event: KeyEvent { logical_key: Key::Named(NamedKey::Escape), .. },
56 ..
57 } => window_target.exit(),
58 _ => (),
59 },
60 _ => ()
61 }
62 }).unwrap();
63}
64
65pub fn gl_config_picker(configs: Box<dyn Iterator<Item = Config> + '_>) -> Config {
66 configs
67 .reduce(|accum, config| {
68 let transparency_check = config.supports_transparency().unwrap_or(false)
69 & !accum.supports_transparency().unwrap_or(false);
70
71 if transparency_check || config.num_samples() > accum.num_samples() {
72 config
73 } else {
74 accum
75 }
76 })
77 .unwrap()
78}
79
80*/