Fix benchmarks for latest glium/glutin API
[mandelwow.git] / text.rs
diff --git a/text.rs b/text.rs
index d1dc7c65f17bb47938474065cfd97b1d7e226bc6..e020156cd08956f226d9c36c0117dcaa24069452 100644 (file)
--- a/text.rs
+++ b/text.rs
@@ -1,7 +1,7 @@
 use cgmath::conv::array4x4;
-use cgmath::{Matrix4, Vector3};
+use cgmath::Matrix4;
 use glium;
-use glium::{Display, Program, Surface, texture};
+use glium::{Display, Program, Surface, implement_vertex, texture, uniform};
 use std;
 
 fn gamma<T>(x: T) -> f32
@@ -22,7 +22,6 @@ where
 
 #[cfg(feature = "image")]
 fn c64_font() -> (u32, u32, Vec<u8>) {
-    use image;
     let image = image::load_from_memory_with_format(
         &include_bytes!("textures/c64-font.png")[..],
         image::PNG,
@@ -52,16 +51,15 @@ struct Vertex {
 }
 implement_vertex!(Vertex, position, tex_coords);
 
-pub struct Text<'a> {
+pub struct Text {
     tex: texture::Texture2d,
     vertex_buffer: glium::VertexBuffer<Vertex>,
     index_buffer: glium::IndexBuffer<u16>,
     program: glium::Program,
-    params: glium::DrawParameters<'a>,
-    model: Matrix4<f32>,
+    params: glium::DrawParameters<'static>,
 }
 
-impl<'a> Text<'a> {
+impl Text {
     pub fn new(display: &Display) -> Text {
         let (w, h, pixels) = c64_font();
         let image = glium::texture::RawImage2d {
@@ -83,19 +81,19 @@ impl<'a> Text<'a> {
                 display,
                 &[
                     Vertex {
-                        position: [-1.0, -1.0],
+                        position: [-0.5, -0.5],
                         tex_coords: [0.0, 1.0],
                     },
                     Vertex {
-                        position: [-1.0, 1.0],
+                        position: [-0.5, 0.5],
                         tex_coords: [0.0, 0.0],
                     },
                     Vertex {
-                        position: [1.0, 1.0],
+                        position: [0.5, 0.5],
                         tex_coords: [1.0, 0.0],
                     },
                     Vertex {
-                        position: [1.0, -1.0],
+                        position: [0.5, -0.5],
                         tex_coords: [1.0, 1.0],
                     },
                 ],
@@ -119,7 +117,6 @@ impl<'a> Text<'a> {
         };
 
         Text {
-            model: Matrix4::from_translation(Vector3::unit_z() * (-1.0)),
             tex: tex,
             vertex_buffer: vertex_buffer,
             index_buffer: index_buffer,
@@ -128,14 +125,14 @@ impl<'a> Text<'a> {
         }
     }
 
-    pub fn draw(&self, frame: &mut glium::Frame, perspview: &[[f32; 4]; 4]) {
+    pub fn draw(&self, frame: &mut glium::Frame, c: char, model: &Matrix4<f32>, perspview: &[[f32; 4]; 4]) {
         let uniforms =
             uniform! {
-            model: array4x4(self.model),
+            model: array4x4(*model),
             perspview: *perspview,
             tex: self.tex.sampled()
                 .magnify_filter(glium::uniforms::MagnifySamplerFilter::Nearest),
-            index: 'C' as i32,
+            index: c as i32,
             // RGB values from http://unusedino.de/ec64/technical/misc/vic656x/colors/
             bgcolor: srgb([ 64,  50, 133u8]),  //  6 - blue
             fgcolor: srgb([120, 106, 189u8]),  // 14 - light blue