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
|
#![allow(dead_code, unused_variables)]
use std::collections::HashMap;
use teleia::*;
struct Assets {
font: font::Bitmap,
shader_flat: shader::Shader,
mesh_square: mesh::Mesh,
texture_test: texture::Texture,
}
impl Assets {
fn new(ctx: &context::Context) -> Self {
Self {
font: font::Bitmap::default(ctx),
shader_flat: shader::Shader::new(
ctx,
include_str!("assets/shaders/flat/vert.glsl"),
include_str!("assets/shaders/flat/frag.glsl"),
),
mesh_square: mesh::Mesh::from_obj(ctx, include_bytes!("assets/meshes/square.obj")),
texture_test: texture::Texture::new(ctx, include_bytes!("assets/textures/test.png")),
}
}
}
pub struct Game {
assets: Assets,
}
impl Game {
pub fn new(ctx: &context::Context) -> Self {
Self {
assets: Assets::new(ctx),
}
}
}
impl teleia::state::Game for Game {
fn initialize_audio(&self, ctx: &context::Context, st: &state::State, actx: &audio::Context) -> HashMap<String, audio::Audio> {
HashMap::from_iter(vec![
("test".to_owned(), audio::Audio::new(&actx, include_bytes!("assets/audio/test.wav"))),
])
}
fn update(&mut self, _ctx: &context::Context, _st: &mut state::State) -> Erm<()> {
Ok(())
}
fn render(&mut self, ctx: &context::Context, st: &mut state::State) -> Erm<()> {
ctx.clear();
self.assets.font.render_text(
ctx, st,
&glam::Vec2::new(0.0, 0.0),
"hello computer",
);
st.bind_2d(ctx, &self.assets.shader_flat);
self.assets.texture_test.bind(ctx);
self.assets.shader_flat.set_position_2d(
ctx, st,
&glam::Vec2::new(40.0, 40.0),
&glam::Vec2::new(16.0, 16.0),
);
self.assets.mesh_square.render(ctx);
Ok(())
}
}
|