Text rendering works, though it's still ugly
parent
6602e36e5b
commit
1c4edfbcd1
|
@ -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 ("checkerboard.png");
|
||||
let texture_font = Texture::from_file ("font.png");
|
||||
|
||||
let (pitch_colors, grass_index) = {
|
||||
let silver = (255.0, 255.0, 255.0);
|
||||
|
@ -818,7 +818,7 @@ impl GameGraphics {
|
|||
];
|
||||
|
||||
let v: Vec <u32> = (0u32..1024).map (|i| {
|
||||
quad.iter ().map (move |j| 6 * i + j)
|
||||
quad.iter ().map (move |j| 4 * i + j)
|
||||
}).flatten ().collect ();
|
||||
gpu_buffers::IndexBuffer::from_slice_u32 (&v)
|
||||
}
|
||||
|
@ -1119,11 +1119,46 @@ impl GameGraphics {
|
|||
Mat4::from_scale ((2.0 / screen_size.0, 2.0 / screen_size.1, 1.0).into ());
|
||||
glezz::uniform_matrix_4fv (unis [&MVP], &mvp);
|
||||
|
||||
let stride_floats = 3 + 2;
|
||||
let stride_bytes = stride_floats * 4;
|
||||
|
||||
let mut vert_buffer = Vec::with_capacity (stride_floats * 1024);
|
||||
|
||||
// X and Y are in screen pixels, c is ASCII
|
||||
let mut add_char = |x: f32, y: f32, c: char| {
|
||||
let c = c as u32 - 1;
|
||||
|
||||
assert! (c >= 0);
|
||||
assert! (c < 128);
|
||||
|
||||
let u = (c % 32) as f32;
|
||||
let v = (c / 32) as f32;
|
||||
|
||||
for vert in &[
|
||||
(0.0, 0.0),
|
||||
(1.0, 0.0),
|
||||
(1.0, 1.0),
|
||||
(0.0, 1.0),
|
||||
] {
|
||||
vert_buffer.push (x + vert.0 * 8.0);
|
||||
vert_buffer.push (y + vert.1 * 18.0);
|
||||
|
||||
vert_buffer.push ((u + vert.0) * 8.0 / 256.0);
|
||||
vert_buffer.push ((v + 1.0 - vert.1) * 18.0 / 256.0);
|
||||
}
|
||||
};
|
||||
|
||||
let s = "Pumpkin";
|
||||
|
||||
for (i, c) in s.chars ().enumerate () {
|
||||
add_char (30.0 + i as f32 * 8.0, 30.0, c);
|
||||
}
|
||||
|
||||
let pos: Vec <f32> = vec! [
|
||||
0.0, 0.0, 0.0,
|
||||
256.0, 0.0, 0.0,
|
||||
256.0, 256.0, 0.0,
|
||||
0.0, 256.0, 0.0,
|
||||
0.0, 0.0,
|
||||
256.0, 0.0,
|
||||
256.0, 256.0,
|
||||
0.0, 256.0,
|
||||
];
|
||||
|
||||
use std::convert::TryInto;
|
||||
|
@ -1144,24 +1179,21 @@ impl GameGraphics {
|
|||
use renderable_model::attributes::*;
|
||||
use std::ffi::c_void;
|
||||
|
||||
gl::BufferSubData (
|
||||
gl::ARRAY_BUFFER,
|
||||
0.try_into ().unwrap (),
|
||||
(4 * 4 * 3).try_into ().unwrap (),
|
||||
&pos [0] as *const f32 as *const c_void
|
||||
);
|
||||
if true {
|
||||
gl::BufferSubData (
|
||||
gl::ARRAY_BUFFER,
|
||||
0.try_into ().unwrap (),
|
||||
(s.len () * 4 * 4 * 4).try_into ().unwrap (),
|
||||
&vert_buffer [0] as *const f32 as *const c_void
|
||||
);
|
||||
|
||||
gl::VertexAttribPointer (attrs [POS].unwrap (), 2, gl::FLOAT, 0u8, 4 * 4, 0 as *const f32 as *const c_void);
|
||||
gl::VertexAttribPointer (attrs [UV].unwrap (), 2, gl::FLOAT, 0u8, 4 * 4, (4 * 2) 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
|
||||
);
|
||||
let num_indices = s.len () as u32 * 6;
|
||||
|
||||
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);
|
||||
gl::DrawRangeElements (gl::TRIANGLES, 0, num_indices, num_indices as i32, gl::UNSIGNED_INT, 0 as *const u32 as *const c_void);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue