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
27 #include "debugging/debugging.h"
29 // LordHavoc: this is code for direct Xlib bitmap character fetching, as an
30 // alternative to requiring gtkglarea, it was created due to a lack of this
31 // package on SuSE 9.x but this package is now commonly shipping in Linux
32 // distributions so this code may be unnecessary, feel free however to enable
33 // it when building packages for distros that do not ship with that package,
34 // or if you just prefer less dependencies...
41 GLFont glfont_create(const char* font_string)
43 GLuint font_list_base;
44 XFontStruct *fontInfo;
45 Display *dpy = GDK_DISPLAY ();
46 unsigned int i, first, last, firstrow, lastrow;
50 fontInfo = XLoadQueryFont (dpy, "-*-fixed-*-*-*-*-8-*-*-*-*-*-*-*");
53 // try to load other fonts
54 fontInfo = XLoadQueryFont (dpy, "-*-fixed-*-*-*-*-*-*-*-*-*-*-*-*");
58 fontInfo = XLoadQueryFont(dpy, "-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
61 ERROR_MESSAGE("couldn't create font");
64 first = (int)fontInfo->min_char_or_byte2;
65 last = (int)fontInfo->max_char_or_byte2;
66 firstrow = (int)fontInfo->min_byte1;
67 lastrow = (int)fontInfo->max_byte1;
69 * How many chars in the charset
71 maxchars = 256 * lastrow + last;
72 font_list_base = glGenLists(maxchars+1);
73 if (font_list_base == 0)
75 ERROR_MESSAGE( "couldn't create font" );
79 * Get offset to first char in the charset
81 firstbitmap = 256 * firstrow + first;
83 * for each row of chars, call glXUseXFont to build the bitmaps.
86 for(i=firstrow; i<=lastrow; i++)
88 glXUseXFont(fontInfo->fid, firstbitmap, last-first+1, font_list_base+firstbitmap);
92 /* *height = fontInfo->ascent + fontInfo->descent;
93 *width = fontInfo->max_bounds.width; */
94 return GLFont(font_list_base, fontInfo->ascent + fontInfo->descent);
97 void glfont_release(GLFont& font)
99 glDeleteLists(font.getDisplayList(), 256);
105 #include <gtk/gtkglwidget.h>
107 GLFont glfont_create(const char* font_string)
109 GLuint font_list_base = glGenLists (256);
110 gint font_height = 0, font_ascent = 0, font_descent = 0;
112 PangoFontDescription* font_desc = pango_font_description_from_string (font_string);
114 PangoFont* font = gdk_gl_font_use_pango_font (font_desc, 0, 256, font_list_base);
118 PangoFontMetrics* font_metrics = pango_font_get_metrics (font, 0);
120 font_ascent = pango_font_metrics_get_ascent (font_metrics);
121 font_descent = pango_font_metrics_get_descent (font_metrics);
122 font_height = font_ascent + font_descent;
124 font_ascent = PANGO_PIXELS (font_ascent);
125 font_descent = PANGO_PIXELS (font_descent);
126 font_height = PANGO_PIXELS (font_height);
128 pango_font_metrics_unref (font_metrics);
131 pango_font_description_free (font_desc);
133 // fix for pango/gtkglext metrix bug
134 if(font_height > 256)
137 return GLFont(font_list_base, font_ascent, font_descent, font_height);
140 void glfont_release(GLFont& font)
142 glDeleteLists(font.getDisplayList(), 256);
143 font = GLFont(0, 0, 0, 0);