18 #include <OpenGL/glu.h> 23 #if defined ALLEGRO_WITH_XWINDOWS && !defined ALLEGROGL_GENERIC_DRIVER 28 #define PREFIX_E "agl-font ERROR: " 38 static AL_CONST FONT_AGL_DATA *find_range(AL_CONST FONT_AGL_DATA *f,
int c) {
41 if ((c >= f->start) && (c < f->end))
68 AL_CONST
char *format, ...) {
74 if (!__allegro_gl_valid_context)
79 uvszprintf(buf, BUF_SIZE, format, ap);
87 c[0] = (GLubyte)getr(color);
88 c[1] = (GLubyte)getg(color);
89 c[2] = (GLubyte)getb(color);
90 c[3] = (__allegro_gl_use_alpha && bitmap_color_depth(screen) == 32)
91 ? (GLubyte)geta(color) : 255;
170 AL_CONST
char *format, ...) {
171 #define BUF_SIZE 1024 175 AL_CONST FONT_AGL_DATA *range = NULL;
178 AL_CONST FONT_AGL_DATA *d;
179 GLint vert_order, cull_mode;
182 int restore_rasterpos = 0;
183 GLuint old_texture_bind = 0;
184 GLfloat old_raster_pos[4];
187 if (!__allegro_gl_valid_context)
192 TRACE(PREFIX_E
"agl_printf: Null parameter\n");
196 if (f->vtable != font_vtable_agl) {
197 TRACE(PREFIX_E
"agl_printf: Font parameter isn't of the AGL " 202 d = (AL_CONST FONT_AGL_DATA*)f->data;
205 va_start(ap, format);
206 uvszprintf(buf, BUF_SIZE, format, ap);
211 glGetIntegerv(GL_MATRIX_MODE, &matrix_mode);
212 glGetIntegerv(GL_FRONT_FACE, &vert_order);
213 glGetIntegerv(GL_CULL_FACE_MODE, &cull_mode);
215 glMatrixMode(GL_MODELVIEW);
222 glGetIntegerv(GL_TEXTURE_BINDING_2D, &temp);
223 old_texture_bind = (GLuint)temp;
227 glTranslatef(0, 0, -1);
228 glBindTexture(GL_TEXTURE_2D, 0);
230 glGetFloatv(GL_CURRENT_RASTER_POSITION, old_raster_pos);
232 restore_rasterpos = 1;
235 glTranslatef(x, y, z);
236 glBindTexture(GL_TEXTURE_2D, 0);
239 glTranslatef(x, y, z);
243 while ((c = ugetc(buf + pos)) != 0) {
247 if ((!range) || (c < range->start) || (c >= range->end)) {
249 range = find_range(d, c);
252 range = find_range(d, (c =
'^'));
261 glBindTexture(GL_TEXTURE_2D, range->texture);
266 c += range->list_base;
275 glMatrixMode(matrix_mode);
276 glFrontFace(vert_order);
277 glCullFace(cull_mode);
279 glBindTexture(GL_TEXTURE_2D, old_texture_bind);
281 if (restore_rasterpos) {
282 glRasterPos4fv(old_raster_pos);
290 #ifndef ALLEGROGL_GENERIC_DRIVER 291 #ifdef ALLEGRO_WINDOWS 293 static FONT *win_load_system_font(
char *name,
int type,
int style,
int w,
int h,
float depth,
int start,
int end) {
300 ret = malloc(
sizeof(FONT));
302 TRACE(PREFIX_E
"win_load_system_font: Ran out of memory " 303 "while allocating %i bytes\n",
sizeof(FONT));
306 data = malloc(
sizeof(FONT_AGL_DATA));
309 TRACE(PREFIX_E
"win_load_system_font: Ran out of memory " 310 "while allocating %i bytes\n",
sizeof(FONT_AGL_DATA));
313 ret->vtable = font_vtable_agl;
316 data->list_base = glGenLists(end - start);
320 data->is_free_chunk = 0;
326 hFont = CreateFont( -h, w,
338 FF_DONTCARE | DEFAULT_PITCH,
341 dc = GetDC(win_get_window());
343 SelectObject(dc, hFont);
345 wglUseFontBitmaps(dc, start, end - start, data->list_base);
352 GLYPHMETRICSFLOAT *gmf;
353 gmf = malloc(
sizeof(GLYPHMETRICSFLOAT) * (end - start));
354 memset(gmf, 0,
sizeof(GLYPHMETRICSFLOAT) * (end - start));
356 hFont = CreateFont( -h, w,
368 FF_DONTCARE | DEFAULT_PITCH,
371 dc = GetDC(win_get_window());
373 SelectObject(dc, hFont);
374 wglUseFontOutlines(dc, start, end - start, data->list_base,
376 ? WGL_FONT_POLYGONS : WGL_FONT_LINES, gmf);
388 #ifdef ALLEGRO_WITH_XWINDOWS 389 static FONT *x_load_system_font(
char *name,
int type,
int style,
int w,
int h,
390 float depth,
int start,
int end) {
395 ret = malloc(
sizeof(FONT));
397 TRACE(PREFIX_E
"x_load_system_font: Ran out of memory " 398 "while allocating %zi bytes\n",
sizeof(FONT));
401 data = malloc(
sizeof(FONT_AGL_DATA));
404 TRACE(PREFIX_E
"x_load_system_font: Ran out of memory " 405 "while allocating %zi bytes\n",
sizeof(FONT_AGL_DATA));
408 ret->vtable = font_vtable_agl;
411 data->list_base = glGenLists(end - start);
415 data->is_free_chunk = 0;
418 char buf[256], major_type[256], minor_type[2];
420 usprintf(major_type,
"medium");
422 usprintf(major_type,
"bold");
424 minor_type[1] =
'\0';
426 usprintf(buf,
"-*-%s-%s-%s-normal-*-%i-*-*-*-*-*-*-*", name,
427 major_type, minor_type, h);
429 xfont = XLoadQueryFont(_xwin.display, buf);
433 TRACE(PREFIX_E
"x_load_system_font: Failed to load " 437 glXUseXFont(xfont->fid, start, end - start, data->list_base);
440 XFreeFont(_xwin.display, xfont);
470 aglf_font_generation_mode = mode;
488 style, w, h, 0.0f, 32, 256);
527 int w,
int h,
float depth,
int start,
int end) {
531 if (!__allegro_gl_valid_context)
535 TRACE(PREFIX_E
"load_system_font: Nameless font\n");
541 #ifndef ALLEGROGL_GENERIC_DRIVER 542 #ifdef ALLEGRO_WINDOWS 543 ret = win_load_system_font(name, type, style, w, h, depth, start, end);
544 #elif defined ALLEGRO_UNIX 546 ret = x_load_system_font(name, type, style, w, h, depth, start, end);
580 if (f->vtable != font_vtable_agl) {
581 TRACE(PREFIX_E
"destroy_font: Font is not of AGL type\n");
588 TRACE(PREFIX_E
"destroy_font: Font is inconsistent\n");
594 FONT_AGL_DATA *datanext;
601 if (__allegro_gl_valid_context) {
603 glDeleteLists(data->list_base, data->end - data->start);
605 glDeleteTextures(1, &data->texture);
614 destroy_bitmap(data->data);
615 if (data->glyph_coords)
616 free(data->glyph_coords);
621 FONT_GLYPH **gl = data->data;
622 for (i = 0; i < data->end - data->start; i++) {
629 datanext = data->next;
631 if (data->is_free_chunk)
697 if (f->vtable != font_vtable_agl) {
698 TRACE(PREFIX_E
"list_font_textures: Font is not of AGL type\n");
705 TRACE(PREFIX_E
"list_font_textures: Font is inconsistent\n");
709 if (!__allegro_gl_valid_context) {
719 if (ids && num_ids < max_num_id) {
720 ids[num_ids] = data->texture;
#define AGL_FONT_STYLE_STRIKEOUT
Creates a font with striked out characters.
int allegro_gl_printf_ex(AL_CONST FONT *f, float x, float y, float z, AL_CONST char *format,...)
Prints a formatted string (printf style) on the screen.
#define AGL_FONT_STYLE_BOLD
Creates a font with bold characters.
void allegro_gl_set_font_generation_mode(int mode)
Set the font generation mode for system fonts.
FONT * allegro_gl_load_system_font_ex(char *name, int type, int style, int w, int h, float depth, int start, int end)
Loads a system font.
void allegro_gl_destroy_font(FONT *f)
void allegro_gl_destroy_font(FONT *usefont)
#define AGL_FONT_STYLE_UNDERLINE
Creates a font with underlined characters.
size_t allegro_gl_list_font_textures(FONT *f, GLuint *ids, size_t max_num_id)
List the texture ID of all textures forming the specified font.
#define AGL_FONT_TYPE_TEXTURED
Indicates that you want fonts to be converted to a texture format.
FONT * allegro_gl_load_system_font(char *name, int style, int w, int h)
Short hand for aglf_load_system_font_ex(name, AGL_FONT_TYPE_OUTLINE, style, w, h, 0...
#define AGL_FONT_STYLE_BLACK
Creates a font with black (strong bold) characters.
#define AGL_FONT_STYLE_ANTI_ALIASED
Creates a font with anti-aliased characters.
#define AGL_FONT_STYLE_ITALIC
Creates a font with italicized characters.
#define AGL_FONT_TYPE_BITMAP
Indicates that you want fonts to be converted to a bitmap format.
#define AGL_FONT_TYPE_OUTLINE
Indicates that you want fonts to be converted to an outline format.
Main header file for AllegroGL.
#define AGL_FONT_TYPE_DONT_CARE
Indicates that you don't really care how a font will be converted.
#define AGL_FONT_POLYGONS
Font generation mode.
int allegro_gl_printf(AL_CONST FONT *f, float x, float y, float z, int color, AL_CONST char *format,...)
Equivalent to: