15 void Font::set_texture(const Texture2D &t)
20 void Font::add_glyph(wchar_t code, float x1, float y1, float x2, float y2, float w, float h, float desc, float adv)
34 float Font::get_string_width(const string &str) const
38 for(string::const_iterator i=str.begin(); i!=str.end(); ++i)
40 GlyphMap::const_iterator j=glyphs.find((unsigned char)*i);
44 const Glyph &glyph=j->second;
52 void Font::draw_string(const string &str) const
59 for(string::const_iterator i=str.begin(); i!=str.end(); ++i)
60 draw_glyph((unsigned char)*i, data, x);
62 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
71 void Font::prepare(float *data) const
75 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
76 glEnableClientState(GL_VERTEX_ARRAY);
77 glTexCoordPointer(2, GL_FLOAT, 4*sizeof(float), data);
78 glVertexPointer(2, GL_FLOAT, 4*sizeof(float), data+2);
81 void Font::draw_glyph(wchar_t code, float *data, float &x) const
83 GlyphMap::const_iterator i=glyphs.find(code);
87 const Glyph &glyph=i->second;
89 data[0]=data[12]=glyph.x1;
90 data[1]=data[5]=glyph.y1;
91 data[4]=data[8]=glyph.x2;
92 data[9]=data[13]=glyph.y2;
95 data[3]=data[7]=glyph.descent;
96 data[6]=data[10]=x+glyph.w;
97 data[11]=data[15]=glyph.h+glyph.descent;
99 glDrawArrays(GL_QUADS, 0, 4);
104 Font::Loader::Loader(Font &f):
107 add("texture", &Loader::texture);
108 add("glyph", &Loader::glyph);
111 void Font::Loader::texture(const string &t)
113 Texture2D *tex=new Texture2D;
114 tex->parameter(GL_GENERATE_MIPMAP, 1);
120 void Font::Loader::glyph(unsigned c)
125 font.glyphs.insert(GlyphMap::value_type(c, gl));
128 Font::Glyph::Loader::Loader(Glyph &g):
131 add("texcoords", &Loader::texcoords);
132 add("size", &Loader::size);
133 add("descent", &Glyph::descent);
134 add("advance", &Glyph::advance);
137 void Font::Glyph::Loader::texcoords(float x1, float y1, float x2, float y2)
145 void Font::Glyph::Loader::size(float w, float h)