14 varray((TEXCOORD2, VERTEX2))
17 void Font::set_texture(const Texture2D &t)
22 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)
35 glyph.index=glyphs.size();
36 glyphs.insert(GlyphMap::value_type(code, glyph));
38 RefPtr<VertexArrayBuilder> va_builder=varray.modify();
39 create_glyph_vertices(glyph, *va_builder);
42 float Font::get_string_width(const string &str) const
46 for(string::const_iterator i=str.begin(); i!=str.end(); ++i)
47 x+=get_glyph_advance(static_cast<unsigned char>(*i));
52 float Font::get_string_width(const wstring &str) const
56 for(wstring::const_iterator i=str.begin(); i!=str.end(); ++i)
57 x+=get_glyph_advance(*i);
62 void Font::draw_string(const string &str) const
66 for(string::const_iterator i=str.begin(); i!=str.end(); ++i)
67 draw_glyph(static_cast<unsigned char>(*i));
72 void Font::draw_string(const wstring &str) const
76 for(wstring::const_iterator i=str.begin(); i!=str.end(); ++i)
88 void Font::create_glyph_vertices()
91 RefPtr<VertexArrayBuilder> va_builder=varray.modify();
94 for(GlyphMap::iterator i=glyphs.begin(); i!=glyphs.end(); ++i, ++n)
97 create_glyph_vertices(i->second, *va_builder);
101 void Font::create_glyph_vertices(const Glyph &glyph, VertexArrayBuilder &va_builder)
103 va_builder.texcoord(glyph.x1, glyph.y1);
104 va_builder.vertex(glyph.off_x, glyph.off_y);
105 va_builder.texcoord(glyph.x2, glyph.y1);
106 va_builder.vertex(glyph.off_x+glyph.w, glyph.off_y);
107 va_builder.texcoord(glyph.x2, glyph.y2);
108 va_builder.vertex(glyph.off_x+glyph.w, glyph.off_y+glyph.h);
109 va_builder.texcoord(glyph.x1, glyph.y2);
110 va_builder.vertex(glyph.off_x, glyph.off_y+glyph.h);
113 void Font::prepare_render() const
120 void Font::draw_glyph(wchar_t code) const
122 GlyphMap::const_iterator i=glyphs.find(code);
126 glDrawArrays(GL_QUADS, i->second.index*4, 4);
128 glTranslatef(i->second.advance, 0, 0);
131 float Font::get_glyph_advance(wchar_t code) const
133 GlyphMap::const_iterator i=glyphs.find(code);
137 return i->second.advance;
141 Font::Loader::Loader(Font &f):
144 add("default_size", &Font::default_size);
145 add("texture", &Loader::texture);
146 add("glyph", &Loader::glyph);
149 Font::Loader::~Loader()
151 font.create_glyph_vertices();
154 void Font::Loader::texture(const string &t)
156 Texture2D *tex=new Texture2D;
157 tex->parameter(GL_GENERATE_MIPMAP, 1);
163 void Font::Loader::glyph(unsigned c)
168 font.glyphs.insert(GlyphMap::value_type(c, gl));
172 Font::Glyph::Loader::Loader(Glyph &g):
175 add("texcoords", &Loader::texcoords);
176 add("size", &Loader::size);
177 add("offset", &Loader::offset);
178 add("advance", &Glyph::advance);
181 void Font::Glyph::Loader::texcoords(float x1, float y1, float x2, float y2)
189 void Font::Glyph::Loader::size(float w, float h)
195 void Font::Glyph::Loader::offset(float x, float y)