1 #include "meshbuilder.h"
10 Text::Text(const Font &f, const Technique *tech):
12 mesh((TEXCOORD2, VERTEX2)),
16 object.set_mesh(&mesh);
21 void Text::set_technique(const Technique *tech)
26 technique.replace_texture("diffusemap", font.get_texture());
27 object.set_technique(&technique);
30 object.set_technique(0);
33 void Text::set_text(const string &text, StringCodec::Decoder &dec)
36 width = font.get_string_width(text, dec);
37 GL::MeshBuilder bld(mesh);
38 bld.matrix() *= Matrix::translation(Vector3(-horz_align*width, vert_offset, 0.0f));
39 font.build_string(text, dec, bld);
48 void Text::set_alignment(HorizontalAlign ha, VerticalAlign va)
53 case LEFT: h = 0.0f; break;
54 case CENTER: h = 0.5f; break;
55 case RIGHT: h = 1.0f; break;
56 default: throw invalid_argument("Text::set_alignment");
62 case DESCENT: v = -font.get_descent(); break;
63 case BASELINE: v = 0.0f; break;
64 case MIDLINE: v = font.get_cap_height()/2; break;
65 case ASCENT: v = font.get_ascent(); break;
66 default: throw invalid_argument("Text::set_alignment");
72 void Text::set_alignment(float h, float v)
74 if(h==horz_align && -v==vert_offset)
77 float horz_adjust = (horz_align-h)*width;
78 float vert_adjust = -v-vert_offset;
82 unsigned pos_offset = mesh.get_vertices().get_format().offset(VERTEX2);
83 unsigned n_vertices = mesh.get_n_vertices();
84 for(unsigned i=0; i<n_vertices; ++i)
86 float *pos = mesh.modify_vertex(i)+pos_offset;
87 pos[0] += horz_adjust;
88 pos[1] += vert_adjust;
92 void Text::render(Renderer &renderer, const Tag &tag) const
94 object.render(renderer, tag);