gust_render/
shared_window.rs1use crate::Vector;
2use color::Color;
3use draw::*;
4use glfw::Context;
5use nalgebra::Matrix4;
6use view::View;
7use window::Window;
8
9pub struct SharedWindow {
11 context: glfw::RenderContext,
12 view: View,
13}
14
15impl SharedWindow {
16 pub fn new(window: &mut Window) -> SharedWindow {
17 SharedWindow {
18 view: window.view().clone(),
19 context: window.win.render_context(),
20 }
21 }
22
23 pub fn active(&mut self) -> bool {
24 self.context.make_current();
25 self.context.is_current()
26 }
27
28 pub fn display(&mut self) {
29 self.active();
30 self.context.swap_buffers();
31 }
32
33 pub fn clear(&self, color: Color) {
34 unsafe {
35 gl::ClearColor(color.0, color.1, color.2, color.3);
36 gl::Clear(gl::COLOR_BUFFER_BIT);
37 }
38 }
39}
40
41impl Drawer for SharedWindow {
42 fn draw<T: Drawable>(&mut self, drawable: &T) {
43 self.active();
44 drawable.draw(self);
45 }
46
47 fn projection(&self) -> &Matrix4<f32> {
48 self.view.projection()
49 }
50
51 fn get_center(&self) -> Vector<f32> {
52 unimplemented!("Think 'bout giving center of view.");
53 }
54
55 fn get_sizes(&self) -> Vector<f32> {
56 unimplemented!("Think 'bout giving sizes of view.");
57 }
58}