-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
text.rs
49 lines (40 loc) 路 1.3 KB
/
text.rs
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
use tetra::graphics::text::{Font, Text};
use tetra::graphics::{self, Color};
use tetra::math::Vec2;
use tetra::{Context, ContextBuilder, State};
const TEXT_OFFSET: Vec2<f32> = Vec2::new(16.0, 16.0);
struct GameState {
vector_text: Text,
bitmap_text: Text,
}
impl GameState {
fn new(ctx: &mut Context) -> tetra::Result<GameState> {
let vector_text = Text::new(
"Hello, world!\n\nThis is some text being rendered from a TTF font.",
Font::vector(ctx, "./examples/resources/DejaVuSansMono.ttf", 16.0)?,
);
let bitmap_text = Text::new(
"Hello, world!\n\nThis is some text being rendered from a bitmap font.",
Font::bmfont(ctx, "./examples/resources/DejaVuSansMono.fnt")?,
);
Ok(GameState {
vector_text,
bitmap_text,
})
}
}
impl State for GameState {
fn draw(&mut self, ctx: &mut Context) -> tetra::Result {
graphics::clear(ctx, Color::rgb(0.392, 0.584, 0.929));
self.vector_text.draw(ctx, TEXT_OFFSET);
self.bitmap_text
.draw(ctx, TEXT_OFFSET + Vec2::new(0.0, 128.0));
Ok(())
}
}
fn main() -> tetra::Result {
ContextBuilder::new("Rendering Text", 1280, 720)
.quit_on_escape(true)
.build()?
.run(GameState::new)
}