🚧 Working on the text stream code

main
_ 2020-03-15 18:14:09 +00:00
parent 26fc58cdd0
commit 6602e36e5b
2 changed files with 41 additions and 21 deletions

View File

@ -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 <u32> = (0u32..6 * 1024).collect ();
let quad = [
0, 1, 2,
0, 2, 3,
];
let v: Vec <u32> = (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 <f32> = 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 <f32> = 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 <u32> = 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);
}
});
}

View File

@ -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
};