miserable failure to get text rendering to work using these 'easy text rendering' tricks. Will be bringing in a third party library which I have to write the damn backend implementation for
This commit is contained in:
@@ -12,108 +12,118 @@ pub struct Text {
|
||||
|
||||
/// Container class which implements drawable.
|
||||
impl Text {
|
||||
|
||||
fn accumulator(depth: f32, accumulator: &mut f32, constant: f32) -> f32{
|
||||
|
||||
let accum = *accumulator;
|
||||
*accumulator += constant;
|
||||
return depth + accum + constant;
|
||||
}
|
||||
///
|
||||
pub fn new(position: (f32, f32),
|
||||
size: (f32, f32),
|
||||
depth: u32) -> Text {
|
||||
let normalized_depth = (depth as f32 / 255.0);
|
||||
|
||||
let mut depth_accumulator = 1.0;
|
||||
let depth_accum_constant = -0.01 as f32;
|
||||
|
||||
let verts = {
|
||||
vec![
|
||||
ColorVertex3D {
|
||||
v_position: [-0.5, -0.5, normalized_depth],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
v_position: [-0.5, -0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)+0.1],
|
||||
color: [1.0, 0.0, 0.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-1.0, 1.0, normalized_depth],
|
||||
v_position: [-1.0, 1.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)+0.1],
|
||||
color: [1.0, 0.8, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-0.25, 0.0, normalized_depth],
|
||||
v_position: [-0.25, 0.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)+0.1],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-0.25, 0.0, normalized_depth],
|
||||
v_position: [-0.25, 0.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [0.8, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-1.0, 1.0, normalized_depth],
|
||||
v_position: [-1.0, 1.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.0, 0.5, normalized_depth],
|
||||
v_position: [0.0, 0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 0.8, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.25, 0.0, normalized_depth],
|
||||
v_position: [0.25, 0.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-1.0, 1.0, normalized_depth],
|
||||
v_position: [-1.0, 1.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 0.8, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.0, 0.5, normalized_depth],
|
||||
v_position: [0.0, 0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.5, -0.5, normalized_depth],
|
||||
v_position: [0.5, -0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-1.0, 1.0, normalized_depth],
|
||||
v_position: [-1.0, 1.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.25, 0.0, normalized_depth],
|
||||
v_position: [0.25, 0.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.25, -0.5, normalized_depth],
|
||||
v_position: [0.25, -0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-1.0, 1.0, normalized_depth],
|
||||
v_position: [-1.0, 1.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.5, -0.5, normalized_depth],
|
||||
v_position: [0.5, -0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.25, -0.5, normalized_depth],
|
||||
v_position: [0.25, -0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-1.0, 1.0, normalized_depth],
|
||||
v_position: [-1.0, 1.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.0, -0.1, normalized_depth],
|
||||
v_position: [0.0, -0.1, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-0.25, -0.5, normalized_depth],
|
||||
v_position: [-0.25, -0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-1.0, 1.0, normalized_depth],
|
||||
v_position: [-1.0, 1.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [0.0, -0.1, normalized_depth],
|
||||
v_position: [0.0, -0.1, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-0.5, -0.5, normalized_depth],
|
||||
v_position: [-0.5, -0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-1.0, 1.0, normalized_depth],
|
||||
v_position: [-1.0, 1.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
},
|
||||
ColorVertex3D {
|
||||
v_position: [-0.25, -0.5, normalized_depth],
|
||||
v_position: [-0.25, -0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)],
|
||||
color: [1.0, 1.0, 1.0, 1.0/255.0],
|
||||
}]
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user