PDA

View Full Version : Help with special characters



malancha
09-27-2004, 09:18 PM
I've been using X Fonts to write text in my OpenGL app for a while now, but when I tried to enable multi-language support, I found that special characters are messing up. I searched these forums and found a few ideas, but haven't been able to get it to work. Can someone please point out where I'm going wrong here? Special characters are simply not being printed correctly -- sometimes I get two random characters in place of the one I want, sometimes I get a different font altogether! I've checked that the font I'm using can display all the characters I need:

Here's the font initialization function.
The fontName string contains "-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*"
The fontBase variable is of type GLuint.

int fontInit(char* fontName)
{
fontBase = glGenLists(256);
if (!glIsList(fontBase))
{
fprintf(stderr, "font_init: Out of display lists. \n");
return -1;
}

Display* display = XOpenDisplay(NULL);
if (display == 0)
{
fprintf(stderr, "XOpenDisplay() failed. \n");
return -1;
}

XFontStruct* font_info = XLoadQueryFont(display, f);
if (!font_info)
{
fprintf(stderr, "XLoadQueryFont() failed.\n");
return -1;
}

int first = font_info->min_char_or_byte2;
int last = font_info->max_char_or_byte2;
glXUseXFont(font_info->fid, first, last-first+1, base+first);

return 0;
}


And here's how I actually display text:


void printString(char* s)
{
if (s && strlen(s))
{
glPushAttrib(GL_LIST_BIT);
glListBase(fontBase);
glCallLists(strlen(s), GL_BYTE, (GLubyte *)s);
glPopAttrib();
}
}


I'm tearing my hair out on this one, any help would be greatly appreciated.

-Malancha