summaryrefslogtreecommitdiff
path: root/src/bin/phosphor_test.rs
blob: 40a85588b068f2eba96e49f56cc183b636867e32 (plain) (blame)
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
81
82
83
84
85
86
87
88
89
#![allow(dead_code)]

// use asbestos::{Shader, ShaderProgram};
use buffer::*;
use phosphor::*;
// use raw_gl_context::GlContext;

fn main() {
    let my_program = MyProgram {};
    let mut wm = WindowManager::with_program(my_program);
    wm.create_window(MainWindow::new());
    wm.run()
}

struct MyProgram {}
impl ProgramController for MyProgram {}

struct MainWindow {
    // program: ShaderProgram,
}
impl MainWindow {
    pub fn new() -> Box<Self> {
        // let vertex_shader = Shader::vertex(include_str!("vertex.vert"));
        // let fragment_shader = Shader::fragment(include_str!("fragment.frag"));
        // let program = ShaderProgram::from_shaders(&[vertex_shader, fragment_shader]);
        // Box::new(Self { program })
        Box::new(Self {})
    }
}
impl WindowController for MainWindow {
    fn render(&mut self, buffer: &mut Buffer, _: RenderHint) {
        println!("Rendering...");
        buffer.fill(Colour::TEAL);
    }

    // fn render_gl(&mut self, _context: &mut GlContext) {
    //     println!("Rendering GL...");
    //     unsafe {
    //         gl::ClearColor(1.0, 0.0, 1.0, 1.0);
    //         gl::Clear(gl::COLOR_BUFFER_BIT);
    //     }
    // }
}

// type Pos = [f32; 2];
// type Color = [f32; 3];
// #[repr(C, packed)]
// struct Vertex(Pos, Color);

// const VERTICES: [Vertex; 3] = [
//     Vertex([-0.5, -0.5], [1.0, 0.0, 0.0]),
//     Vertex([0.5,  -0.5], [0.0, 1.0, 0.0]),
//     Vertex([0.0,   0.5], [0.0, 0.0, 1.0])
// ];

// pub struct Buffer {
//     pub id: GLuint,
//     target: GLuint,
// }
// impl Buffer {
//     pub unsafe fn new(target: GLuint) -> Self {
//         let mut id: GLuint = 0;
//         gl::GenBuffers(1, &mut id);
//         Self { id, target }
//     }

//     pub unsafe fn bind(&self) {
//         gl::BindBuffer(self.target, self.id);
//     }

//     pub unsafe fn set_data<D>(&self, data: &[D], usage: GLuint) {
//         self.bind();
//         let (_, data_bytes, _) = data.align_to::<u8>();
//         gl::BufferData(
//             self.target,
//             data_bytes.len() as GLsizeiptr,
//             data_bytes.as_ptr() as *const _,
//             usage,
//         );
//     }
// }

// impl Drop for Buffer {
//     fn drop(&mut self) {
//         unsafe {
//             gl::DeleteBuffers(1, [self.id].as_ptr());
//         }
//     }
// }