text_test/
text_test.rs

1extern crate glium_graphics;
2extern crate graphics;
3extern crate piston;
4
5use glium_graphics::{Glium2d, GliumWindow, GlyphCache, OpenGL, TextureSettings};
6use piston::event_loop::EventLoop;
7use piston::input::RenderEvent;
8use piston::window::WindowSettings;
9use std::path::Path;
10
11fn main() {
12    let opengl = OpenGL::V3_2;
13    let size = [500, 300];
14    let ref mut window: GliumWindow = WindowSettings::new("gfx_graphics: text_test", size)
15        .exit_on_esc(true)
16        .graphics_api(opengl)
17        .build()
18        .unwrap();
19
20    let mut glyph_cache = GlyphCache::new(
21        Path::new("assets/FiraSans-Regular.ttf"),
22        window.clone(),
23        TextureSettings::new(),
24    )
25    .unwrap();
26
27    let mut g2d = Glium2d::new(opengl, window);
28    window.set_lazy(true);
29    while let Some(e) = window.next() {
30        if let Some(args) = e.render_args() {
31            let mut target = window.draw();
32            g2d.draw(&mut target, args.viewport(), |c, g| {
33                use graphics::*;
34
35                clear([1.0; 4], g);
36                text::Text::new_color([0.0, 0.5, 0.0, 1.0], 32)
37                    .draw(
38                        "Hello glium_graphics!",
39                        &mut glyph_cache,
40                        &DrawState::default(),
41                        c.transform.trans(10.0, 100.0),
42                        g,
43                    )
44                    .unwrap();
45            });
46            target.finish().unwrap();
47        }
48    }
49}