From 6602e36e5b61e4324df15962bd3395107ef49870 Mon Sep 17 00:00:00 2001 From: _ <> Date: Sun, 15 Mar 2020 18:14:09 +0000 Subject: [PATCH] :construction: Working on the text stream code --- src/bin/pumpkin.rs | 58 +++++++++++++++++++++++++++++++--------------- src/texture.rs | 4 ++-- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/bin/pumpkin.rs b/src/bin/pumpkin.rs index 821f445..2b38c2a 100644 --- a/src/bin/pumpkin.rs +++ b/src/bin/pumpkin.rs @@ -561,7 +561,7 @@ impl GameGraphics { let texture_sky = Texture::from_file ("sky.png"); let texture_grass = Texture::from_file ("grass.png"); - let texture_font = Texture::from_file ("font.png"); + let texture_font = Texture::from_file ("checkerboard.png"); let (pitch_colors, grass_index) = { let silver = (255.0, 255.0, 255.0); @@ -812,7 +812,14 @@ impl GameGraphics { let text_stream = TriangleStream { verts: gpu_buffers::VertexBuffer::streaming (4 * 5 * 6 * 1024), indices: { - let v: Vec = (0u32..6 * 1024).collect (); + let quad = [ + 0, 1, 2, + 0, 2, 3, + ]; + + let v: Vec = (0u32..1024).map (|i| { + quad.iter ().map (move |j| 6 * i + j) + }).flatten ().collect (); gpu_buffers::IndexBuffer::from_slice_u32 (&v) } }; @@ -1107,41 +1114,54 @@ impl GameGraphics { let font_size = (8.0, 18.0); - let mvp = Mat4::from_scale ((2.0 * 256.0 / screen_size.0, 2.0 * 256.0 / screen_size.1, 1.0).into ()); + let mvp = + Mat4::from_translation (Vec3::from ((-1.0, -1.0, 0.0))) * + Mat4::from_scale ((2.0 / screen_size.0, 2.0 / screen_size.1, 1.0).into ()); glezz::uniform_matrix_4fv (unis [&MVP], &mvp); let pos: Vec = vec! [ - -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - -1.0, 1.0, 0.0, + 256.0, 0.0, 0.0, + 256.0, 256.0, 0.0, + 0.0, 256.0, 0.0, ]; use std::convert::TryInto; + let eps = 0.0 / 256.0; + let uv: Vec = vec! [ - 0.0, 1.0, - 1.0, 1.0, - 1.0, 0.0, - 0.0, 0.0, + 0.0 + eps, 1.0 + eps, + 1.0 + eps, 1.0 + eps, + 1.0 + eps, 0.0 + eps, + 0.0 + eps, 0.0 + eps, ]; - let indices: Vec = vec! [ - 0, 1, 2, - 0, 2, 3, - ]; + self.text_stream.verts.bind (); + self.text_stream.indices.bind (); unsafe { use renderable_model::attributes::*; use std::ffi::c_void; - gl::BindBuffer (gl::ARRAY_BUFFER, 0); - gl::BindBuffer (gl::ELEMENT_ARRAY_BUFFER, 0); + gl::BufferSubData ( + gl::ARRAY_BUFFER, + 0.try_into ().unwrap (), + (4 * 4 * 3).try_into ().unwrap (), + &pos [0] as *const f32 as *const c_void + ); - gl::VertexAttribPointer (attrs [POS].unwrap (), 3, gl::FLOAT, 0u8, 4 * 3, &pos [0] as *const f32 as *const c_void); - gl::VertexAttribPointer (attrs [UV].unwrap (), 2, gl::FLOAT, 0u8, 4 * 2, &uv [0] as *const f32 as *const c_void); + gl::BufferSubData ( + gl::ARRAY_BUFFER, + (4 * 4 * 3).try_into ().unwrap (), + (4 * 4 * 2).try_into ().unwrap (), + &uv [0] as *const f32 as *const c_void + ); - gl::DrawRangeElements (gl::TRIANGLES, 0, 6, 6, gl::UNSIGNED_INT, &indices [0] as *const u32 as *const c_void); + gl::VertexAttribPointer (attrs [POS].unwrap (), 3, gl::FLOAT, 0u8, 4 * 3, 0 as *const f32 as *const c_void); + gl::VertexAttribPointer (attrs [UV].unwrap (), 2, gl::FLOAT, 0u8, 4 * 2, (4 * 4 * 3) as *const f32 as *const c_void); + + gl::DrawRangeElements (gl::TRIANGLES, 0, 6, 6, gl::UNSIGNED_INT, 0 as *const u32 as *const c_void); } }); } diff --git a/src/texture.rs b/src/texture.rs index ad0888d..bc2d691 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -39,8 +39,8 @@ impl Texture { gl::TexParameteri (gl::TEXTURE_2D, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE as i32); gl::TexParameteri (gl::TEXTURE_2D, gl::TEXTURE_WRAP_T, gl::CLAMP_TO_EDGE as i32); - gl::TexParameteri (gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST as i32); - gl::TexParameteri (gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::NEAREST as i32); + gl::TexParameteri (gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEAR as i32); + gl::TexParameteri (gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::LINEAR as i32); id };