2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "debugging/debugging.h"
26 // LordHavoc: this is code for direct Xlib bitmap character fetching, as an
27 // alternative to requiring gtkglarea, it was created due to a lack of this
28 // package on SuSE 9.x but this package is now commonly shipping in Linux
29 // distributions so this code may be unnecessary, feel free however to enable
30 // it when building packages for distros that do not ship with that package,
31 // or if you just prefer less dependencies...
38 GLFont glfont_create(const char* font_string)
40 GLuint font_list_base;
41 XFontStruct *fontInfo;
42 Display *dpy = GDK_DISPLAY ();
43 unsigned int i, first, last, firstrow, lastrow;
47 fontInfo = XLoadQueryFont (dpy, "-*-fixed-*-*-*-*-8-*-*-*-*-*-*-*");
50 // try to load other fonts
51 fontInfo = XLoadQueryFont (dpy, "-*-fixed-*-*-*-*-*-*-*-*-*-*-*-*");
55 fontInfo = XLoadQueryFont(dpy, "-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
58 ERROR_MESSAGE("couldn't create font");
61 first = (int)fontInfo->min_char_or_byte2;
62 last = (int)fontInfo->max_char_or_byte2;
63 firstrow = (int)fontInfo->min_byte1;
64 lastrow = (int)fontInfo->max_byte1;
66 * How many chars in the charset
68 maxchars = 256 * lastrow + last;
69 font_list_base = glGenLists(maxchars+1);
70 if (font_list_base == 0)
72 ERROR_MESSAGE( "couldn't create font" );
76 * Get offset to first char in the charset
78 firstbitmap = 256 * firstrow + first;
80 * for each row of chars, call glXUseXFont to build the bitmaps.
83 for(i=firstrow; i<=lastrow; i++)
85 glXUseXFont(fontInfo->fid, firstbitmap, last-first+1, font_list_base+firstbitmap);
89 /* *height = fontInfo->ascent + fontInfo->descent;
90 *width = fontInfo->max_bounds.width; */
91 return GLFont(font_list_base, fontInfo->ascent + fontInfo->descent);
94 void glfont_release(GLFont& font)
96 glDeleteLists(font.getDisplayList(), 256);
102 #include <gtk/gtkglwidget.h>
104 GLFont glfont_create(const char* font_string)
106 GLuint font_list_base = glGenLists (256);
107 gint font_height = 0;
109 PangoFontDescription* font_desc = pango_font_description_from_string (font_string);
111 PangoFont* font = gdk_gl_font_use_pango_font (font_desc, 0, 256, font_list_base);
115 PangoFontMetrics* font_metrics = pango_font_get_metrics (font, 0);
117 font_height = pango_font_metrics_get_ascent (font_metrics) +
118 pango_font_metrics_get_descent (font_metrics);
119 font_height = PANGO_PIXELS (font_height);
121 pango_font_metrics_unref (font_metrics);
124 pango_font_description_free (font_desc);
126 // fix for pango/gtkglext metrix bug
130 return GLFont(font_list_base, font_height);
133 void glfont_release(GLFont& font)
135 glDeleteLists(font.getDisplayList(), 256);