1 use cgmath::conv::array4x4;
2 use cgmath::{Matrix4, One};
4 use glium::{Surface, texture};
13 implement_vertex!(Vertex, position, tex_coords);
16 tex: texture::CompressedSrgbTexture2d,
17 vertex_buffer: glium::VertexBuffer<Vertex>,
18 index_buffer: glium::IndexBuffer<u16>,
19 program: glium::Program,
20 params: glium::DrawParameters<'a>,
25 pub fn new(display: &glium::Display) -> Text {
26 let image = image::load(Cursor::new(&include_bytes!("c64-font.png")[..]), image::PNG)
29 let dimensions = image.dimensions();
31 glium::texture::RawImage2d::from_raw_rgba_reversed(image.into_raw(), dimensions);
32 let tex = glium::texture::CompressedSrgbTexture2d::new(display, image).unwrap();
34 // building the vertex buffer, which contains all the vertices that we will draw
36 glium::VertexBuffer::new(
40 position: [-1.0, -1.0],
41 tex_coords: [0.0, 0.0],
44 position: [-1.0, 1.0],
45 tex_coords: [0.0, 1.0],
49 tex_coords: [1.0, 1.0],
52 position: [1.0, -1.0],
53 tex_coords: [1.0, 0.0],
59 let index_buffer = glium::IndexBuffer::new(
61 glium::index::PrimitiveType::TriangleStrip,
65 // compiling shaders and linking them together
66 let program = program!(display,
72 uniform mat4 perspview;
77 out vec2 v_tex_coords;
80 gl_Position = perspview * model * vec4(position, 0.0, 1.0);
81 // Characters are arranged in a 16x16 square.
82 // Texture oordinates originate in the bottom-left corner.
83 v_tex_coords = (tex_coords) / 16.0 + vec2(0. / 16., 15. / 16.);
89 uniform sampler2D tex;
94 f_color = texture(tex, v_tex_coords);
99 let params = glium::DrawParameters {
100 depth: glium::Depth {
101 test: glium::draw_parameters::DepthTest::IfLess,
110 model: Matrix4::one(),
112 vertex_buffer: vertex_buffer,
113 index_buffer: index_buffer,
119 pub fn draw(&self, frame: &mut glium::Frame, perspview: &[[f32; 4]; 4]) {
120 let uniforms = uniform! {
121 model: array4x4(self.model),
122 perspview: *perspview,
123 tex: self.tex.sampled()
124 //.minify_filter(glium::uniforms::MinifySamplerFilter::Nearest)
125 .magnify_filter(glium::uniforms::MagnifySamplerFilter::Nearest),