+ for (which = 0; which < data->ntextures; which++)
+ {
+ /* Create a pixmap big enough to fit every character in the font.
+ (modulo the "ntextures" scaling.)
+ Make it square-ish, since GL likes dimensions to be powers of 2.
+ */
+ XGCValues gcv;
+ GC gc;
+ Pixmap p;
+ int cw = f->max_bounds.rbearing - f->min_bounds.lbearing;
+ int ch = f->max_bounds.ascent + f->max_bounds.descent;
+ int grid_size = (16 / data->grid_mag);
+ int w = cw * grid_size;
+ int h = ch * grid_size;
+ int i;
+
+ data->cell_width = cw;
+ data->cell_height = ch;
+
+ p = XCreatePixmap (dpy, root, w, h, xgwa.depth);
+ gcv.font = f->fid;
+ gcv.foreground = BlackPixelOfScreen (xgwa.screen);
+ gcv.background = BlackPixelOfScreen (xgwa.screen);
+ gc = XCreateGC (dpy, p, (GCFont|GCForeground|GCBackground), &gcv);
+ XFillRectangle (dpy, p, gc, 0, 0, w, h);
+ XSetForeground (dpy, gc, WhitePixelOfScreen (xgwa.screen));
+ for (i = 0; i < 256 / data->ntextures; i++)
+ {
+ int ii = (i + (which * 256 / data->ntextures));
+ char c = (char) ii;
+ int x = (i % grid_size) * cw;
+ int y = (i / grid_size) * ch;
+
+ /* See comment in print_texture_string for bit layout explanation.
+ */
+ int lbearing = (f->per_char && ii >= f->min_char_or_byte2
+ ? f->per_char[ii - f->min_char_or_byte2].lbearing
+ : f->min_bounds.lbearing);
+ int ascent = (f->per_char && ii >= f->min_char_or_byte2
+ ? f->per_char[ii - f->min_char_or_byte2].ascent
+ : f->max_bounds.ascent);
+ int width = (f->per_char && ii >= f->min_char_or_byte2
+ ? f->per_char[ii - f->min_char_or_byte2].width
+ : f->max_bounds.width);
+
+ if (width == 0) continue;
+ XDrawString (dpy, p, gc, x - lbearing, y + ascent, &c, 1);
+ }
+ XFreeGC (dpy, gc);
+
+ glGenTextures (1, &data->texid[which]);
+ glBindTexture (GL_TEXTURE_2D, data->texid[which]);
+ check_gl_error ("texture font load");
+ data->tex_width = w;
+ data->tex_height = h;