diff options
Diffstat (limited to 'crates/client/src/common')
| -rw-r--r-- | crates/client/src/common/client.rs | 48 | ||||
| -rw-r--r-- | crates/client/src/common/client/assets.rs | 23 | ||||
| -rw-r--r-- | crates/client/src/common/client/assets/audio/test.wav | bin | 0 -> 924 bytes | |||
| -rw-r--r-- | crates/client/src/common/client/assets/meshes/square.obj | 15 | ||||
| -rw-r--r-- | crates/client/src/common/client/assets/shaders/flat/frag.glsl | 11 | ||||
| -rw-r--r-- | crates/client/src/common/client/assets/shaders/flat/vert.glsl | 4 | ||||
| -rw-r--r-- | crates/client/src/common/client/assets/textures/test.png | bin | 0 -> 714 bytes |
7 files changed, 101 insertions, 0 deletions
diff --git a/crates/client/src/common/client.rs b/crates/client/src/common/client.rs new file mode 100644 index 0000000..69ac6b3 --- /dev/null +++ b/crates/client/src/common/client.rs @@ -0,0 +1,48 @@ +#![allow(dead_code, unused_variables)] +mod assets; + +use std::collections::HashMap; +use teleia::*; + +pub struct Game { + assets: assets::Assets, +} + +impl Game { + pub async fn new(ctx: &context::Context) -> Self { + Self { + assets: 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!("client/assets/audio/test.wav"))), + ]) + } + fn finish_title(&mut self, _st: &mut state::State) {} + fn mouse_press(&mut self, _ctx: &context::Context, _st: &mut state::State) {} + fn mouse_move(&mut self, _ctx: &context::Context, _st: &mut state::State, _x: i32, _y: i32) {} + fn update(&mut self, ctx: &context::Context, _st: &mut state::State) -> Option<()> { + Some(()) + } + fn render(&mut self, ctx: &context::Context, st: &mut state::State) -> Option<()> { + ctx.clear(); + self.assets.font.render_text( + ctx, + &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, + &glam::Vec2::new(40.0, 40.0), + &glam::Vec2::new(16.0, 16.0), + ); + self.assets.mesh_square.render(ctx); + Some(()) + } +} diff --git a/crates/client/src/common/client/assets.rs b/crates/client/src/common/client/assets.rs new file mode 100644 index 0000000..742f9ea --- /dev/null +++ b/crates/client/src/common/client/assets.rs @@ -0,0 +1,23 @@ +use teleia::*; + +pub struct Assets { + pub font: font::Bitmap, + pub shader_flat: shader::Shader, + pub mesh_square: mesh::Mesh, + pub texture_test: texture::Texture, +} + +impl Assets { + pub fn new(ctx: &context::Context) -> Self { + Self { + font: font::Bitmap::new(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")), + } + } +} diff --git a/crates/client/src/common/client/assets/audio/test.wav b/crates/client/src/common/client/assets/audio/test.wav Binary files differnew file mode 100644 index 0000000..0eabe85 --- /dev/null +++ b/crates/client/src/common/client/assets/audio/test.wav diff --git a/crates/client/src/common/client/assets/meshes/square.obj b/crates/client/src/common/client/assets/meshes/square.obj new file mode 100644 index 0000000..7328a6c --- /dev/null +++ b/crates/client/src/common/client/assets/meshes/square.obj @@ -0,0 +1,15 @@ +# Blender 3.6.2 +# www.blender.org +o Cube +v -1.000000 -1.000000 0.000000 +v 1.000000 -1.000000 0.000000 +v -1.000000 1.000000 0.000000 +v 1.000000 1.000000 0.000000 +vn -0.0000 -0.0000 -1.0000 +vt 0.0 1.0 +vt 1.0 0.0 +vt 0.0 0.0 +vt 1.0 1.0 +s 0 +f 3/1/1 2/2/1 1/3/1 +f 3/1/1 4/4/1 2/2/1 diff --git a/crates/client/src/common/client/assets/shaders/flat/frag.glsl b/crates/client/src/common/client/assets/shaders/flat/frag.glsl new file mode 100644 index 0000000..7006a2b --- /dev/null +++ b/crates/client/src/common/client/assets/shaders/flat/frag.glsl @@ -0,0 +1,11 @@ +uniform sampler2D texture_data; + +void main() +{ + vec2 tcfull = vec2(vertex_texcoord.x, 1.0 - vertex_texcoord.y); + vec4 texel = texture(texture_data, tcfull); + if (texel.a != 1.0) { + discard; + } + frag_color = texel; +} diff --git a/crates/client/src/common/client/assets/shaders/flat/vert.glsl b/crates/client/src/common/client/assets/shaders/flat/vert.glsl new file mode 100644 index 0000000..e324f7e --- /dev/null +++ b/crates/client/src/common/client/assets/shaders/flat/vert.glsl @@ -0,0 +1,4 @@ +void main() +{ + default_main(); +}
\ No newline at end of file diff --git a/crates/client/src/common/client/assets/textures/test.png b/crates/client/src/common/client/assets/textures/test.png Binary files differnew file mode 100644 index 0000000..1f1edca --- /dev/null +++ b/crates/client/src/common/client/assets/textures/test.png |
