40
40
extern char *progname;
43
#undef DEBUG /* Defining this causes check_gl_error() to be called inside
44
time-critical sections, which could slow things down (since
45
it might result in a round-trip, and stall of the pipeline.)
43
49
/* Loads the font named by the X resource "res".
44
50
Returns an XFontStruct.
45
51
Also converts the font to a set of GL lists and returns the first list.
131
/* Width of the string in pixels.
137
/* Width (and optionally height) of the string in pixels.
134
string_width (XFontStruct *f, const char *c)
140
string_width (XFontStruct *f, const char *c, int *height_ret)
144
int h = f->ascent + f->descent;
139
147
int cc = *((unsigned char *) c);
141
? f->per_char[cc-f->min_char_or_byte2].rbearing
142
: f->min_bounds.rbearing);
150
if (x > max_w) max_w = x;
152
h += f->ascent + f->descent;
156
? f->per_char[cc-f->min_char_or_byte2].width
157
: f->min_bounds.rbearing);
160
if (x > max_w) max_w = x;
161
if (height_ret) *height_ret = h;
157
175
GLuint font_dlist,
158
176
int window_width, int window_height,
159
177
GLfloat x, GLfloat y,
179
Bool clear_background_p)
162
181
GLfloat line_height = font->ascent + font->descent;
163
182
GLfloat sub_shift = (line_height * 0.3);
164
int cw = string_width (font, "m");
183
int cw = string_width (font, "m", 0);
165
184
int tabs = cw * 7;
167
186
y -= line_height;
188
/* Sadly, this causes a stall of the graphics pipeline (as would the
189
equivalent calls to glGet*.) But there's no way around this, short
190
of having each caller set up the specific display matrix we need
191
here, which would kind of defeat the purpose of centralizing this
169
194
glPushAttrib (GL_TRANSFORM_BIT | /* for matrix contents */
170
GL_ENABLE_BIT); /* for various glDisable calls */
171
glDisable (GL_LIGHTING);
172
glDisable (GL_DEPTH_TEST);
173
glDisable (GL_TEXTURE_2D);
195
GL_ENABLE_BIT | /* for various glDisable calls */
196
GL_CURRENT_BIT | /* for glColor3f() */
197
GL_LIST_BIT); /* for glListBase() */
200
check_gl_error ("glPushAttrib");
203
/* disable lighting and texturing when drawing bitmaps!
204
(glPopAttrib() restores these.)
206
glDisable (GL_TEXTURE_2D);
207
glDisable (GL_LIGHTING);
208
glDisable (GL_BLEND);
209
glDisable (GL_DEPTH_TEST);
210
glDisable (GL_CULL_FACE);
212
/* glPopAttrib() does not restore matrix changes, so we must
213
push/pop the matrix stacks to be non-intrusive there.
175
215
glMatrixMode(GL_PROJECTION);
219
check_gl_error ("glPushMatrix");
178
221
glLoadIdentity();
223
/* Each matrix mode has its own stack, so we need to push/pop
180
225
glMatrixMode(GL_MODELVIEW);
185
230
Bool sub_p = False;
233
check_gl_error ("glPushMatrix");
186
236
glLoadIdentity();
188
237
gluOrtho2D (0, window_width, 0, window_height);
239
check_gl_error ("gluOrtho2D");
242
if (clear_background_p)
245
int lh = font->ascent + font->descent;
246
w = string_width (font, string, &h);
248
glRecti (x - font->descent,
250
x + w + 2*font->descent,
251
y + lh - h - font->descent);
190
256
glRasterPos2f (x, y);
257
/* glListBase (font_dlist);*/
191
258
for (i = 0; i < strlen(string); i++)
193
260
unsigned char c = (unsigned char) string[i];
285
/* glCallLists (s - string, GL_UNSIGNED_BYTE, string);*/
218
286
glCallList (font_dlist + (int)(c));
219
287
x2 += (font->per_char
220
288
? font->per_char[c - font->min_char_or_byte2].width
221
289
: font->min_bounds.width);
293
check_gl_error ("print_gl_string");