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