16 varray((TEXCOORD2, VERTEX2))
19 void Font::set_texture(const Texture2D &t)
24 void Font::add_glyph(wchar_t code, float x1, float y1, float x2, float y2, float w, float h, float ox, float oy, float adv)
37 glyph.index=glyphs.size();
38 glyphs.insert(GlyphMap::value_type(code, glyph));
40 RefPtr<VertexArrayBuilder> va_builder=varray.modify();
41 create_glyph_vertices(glyph, *va_builder);
44 float Font::get_string_width(const string &str) const
48 for(string::const_iterator i=str.begin(); i!=str.end(); ++i)
49 x+=get_glyph_advance(static_cast<unsigned char>(*i));
54 float Font::get_string_width(const wstring &str) const
58 for(wstring::const_iterator i=str.begin(); i!=str.end(); ++i)
59 x+=get_glyph_advance(*i);
64 void Font::draw_string(const string &str) const
68 for(string::const_iterator i=str.begin(); i!=str.end(); ++i)
69 draw_glyph(static_cast<unsigned char>(*i));
74 void Font::draw_string(const wstring &str) const
78 for(wstring::const_iterator i=str.begin(); i!=str.end(); ++i)
90 void Font::create_glyph_vertices()
93 RefPtr<VertexArrayBuilder> va_builder=varray.modify();
96 for(GlyphMap::iterator i=glyphs.begin(); i!=glyphs.end(); ++i, ++n)
99 create_glyph_vertices(i->second, *va_builder);
103 void Font::create_glyph_vertices(const Glyph &glyph, VertexArrayBuilder &va_builder)
105 va_builder.texcoord(glyph.x1, glyph.y1);
106 va_builder.vertex(glyph.off_x, glyph.off_y);
107 va_builder.texcoord(glyph.x2, glyph.y1);
108 va_builder.vertex(glyph.off_x+glyph.w, glyph.off_y);
109 va_builder.texcoord(glyph.x2, glyph.y2);
110 va_builder.vertex(glyph.off_x+glyph.w, glyph.off_y+glyph.h);
111 va_builder.texcoord(glyph.x1, glyph.y2);
112 va_builder.vertex(glyph.off_x, glyph.off_y+glyph.h);
115 void Font::prepare_render() const
122 void Font::draw_glyph(wchar_t code) const
124 GlyphMap::const_iterator i=glyphs.find(code);
128 glDrawArrays(GL_QUADS, i->second.index*4, 4);
130 glTranslatef(i->second.advance, 0, 0);
133 float Font::get_glyph_advance(wchar_t code) const
135 GlyphMap::const_iterator i=glyphs.find(code);
139 return i->second.advance;
143 Font::Loader::Loader(Font &f):
146 add("default_size", &Font::default_size);
147 add("ascent", &Font::ascent);
148 add("descent", &Font::descent);
149 add("texture", &Loader::texture);
150 add("glyph", &Loader::glyph);
153 Font::Loader::~Loader()
155 font.create_glyph_vertices();
158 void Font::Loader::texture(const string &t)
160 Texture2D *tex=new Texture2D;
161 tex->parameter(GL_GENERATE_MIPMAP, 1);
167 void Font::Loader::glyph(unsigned c)
172 font.glyphs.insert(GlyphMap::value_type(c, gl));
176 Font::Glyph::Loader::Loader(Glyph &g):
179 add("texcoords", &Loader::texcoords);
180 add("size", &Loader::size);
181 add("offset", &Loader::offset);
182 add("advance", &Glyph::advance);
185 void Font::Glyph::Loader::texcoords(float x1, float y1, float x2, float y2)
193 void Font::Glyph::Loader::size(float w, float h)
199 void Font::Glyph::Loader::offset(float x, float y)