View Full Version : printing text (in Linux)

01-30-2004, 06:11 AM
At the moment, I have simple bitmap fonts implemented in Linux.
They work for simple strings, for the ASCII character set from 32 to 127. The code to build the font is shown below.
I tried to load more of the character set by changing the 96 in the code below to (96 + 128), as I want to print out the degree symbol (character \xb0 = 176. It doesn't work, this despite the fact that I can write a console application to print the character and it does work.

I'm posting this here because I think it's probably more an OpenGL issue than a Linux font issue. The font is specified as unsigned byte, so I don't think it's an array offset problem.

Thanks for any help you can give!

GLuint GLpp::buildFont(const char fontName[]) {
int base = glGenLists(96); // storage for 96 characters.

// load the font. what fonts any of you have is going
// to be system dependent, but on my system they are
// in /usr/X11R6/lib/X11/fonts/*, with fonts.alias and
// fonts.dir explaining what fonts the .pcf.gz files
// are. in any case, one of these 2 fonts should be
// on your system...or you won't see any text.

// get the current display. This opens a second
// connection to the display in the DISPLAY environment
// value, and will be around only long enough to load
// the font.
Display* dpy = XOpenDisplay(NULL); // default to DISPLAY env.
XFontStruct* fontInfo = XLoadQueryFont(dpy, fontName);
if (fontInfo == NULL) {
fontInfo = XLoadQueryFont(dpy, "fixed");
if (fontInfo == NULL) {
// cerr << "font load failure\n";
throw "FontFailureTantrum";
after loading this font info, this would probably be the time
to rotate, scale, or otherwise twink your fonts.

start at character 32 (space),
get 96 characters (a few characters past z), and
store them starting at base.
glXUseXFont(fontInfo->fid, 32, 96, base);
XFreeFont(dpy, fontInfo); // free X font info now once copied into OpenGL
XCloseDisplay(dpy); // close down the 2nd display connection.
return base;

[This message has been edited by dovkruger (edited 01-30-2004).]

01-30-2004, 07:11 PM
Moving this post to the Linux specific forum.

01-31-2004, 12:56 AM
Originally posted by dovkruger:
if (fontInfo == NULL) {
fontInfo = XLoadQueryFont(dpy, "fixed");
if (fontInfo == NULL) {
throw "FontFailureTantrum";

your program is leaking displays.

Char 32 is space. You want 176, i.e. you want 145 elements. Does that help? You said you changed this, but you don't say which characters you can't print.