PDA

View Full Version : Greek fonts in windows + opengl



dvm
04-16-2005, 03:19 PM
Hi,
I'm trying to print some greek text in my opengl window, but the letters seem to be selective. I mean not all letters come up. For example I can print a lamda, but can't print an omikron (o). Are there any examples that you know of that show how to use greek characters with opengl?

Just for reference here are my functions (taken from OpenGL Game Programming):

unsigned int CreateOutlineFont(char *fontName, int fontSize, float depth)
{
HFONT hFont; // windows font
unsigned int base;

base = glGenLists(256); // create storage for 96 characters

if (stricmp(fontName, "symbol") == 0)
{
hFont = CreateFont(fontSize, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, SYMBOL_CHARSET,
OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
FF_DONTCARE | DEFAULT_PITCH, fontName);
}
else
{
hFont = CreateFont(fontSize, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, GREEK_CHARSET,
OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
FF_DONTCARE | DEFAULT_PITCH, fontName);
}

if (!hFont)
return 0;

SelectObject(g_HDC, hFont);
wglUseFontOutlines(g_HDC, 0, 255, base, 0.0f, depth, WGL_FONT_POLYGONS, gmf);

return base;
}


void PrintString(unsigned int base, char *str)
{
float length = 0;

if ((str == NULL))
return;

// center the text
for (unsigned int loop=0;loop<(strlen(str));loop++) // find length of text
{
length+=gmf[str[loop]].gmfCellIncX; // increase length by character's width
}
glTranslatef(-length/2,0.0f,0.0f); // translate to center text

// draw the text
glPushAttrib(GL_LIST_BIT);
glListBase(base);
glCallLists(strlen(str), GL_UNSIGNED_BYTE, str);
glPopAttrib();
}

// and in my render (display) function:
PrintString(listBase, "&amp;#972;&amp;#955;&amp;#959;&amp;#953;");Another problem is that if one character that can't be printed is in the string, the whole string doesn't show up.

PS: The numbers in the PrintString call are actually a greek string that got messed up during posting.

T101
04-17-2005, 04:20 AM
I think the issue is that the Greek characters (Unicode I presume) don't map to 0..255.

dvm
04-17-2005, 09:23 AM
Actually, since I ask for GREEK_CHARSET in CreateFont that shouldn't be a problem. I've checked with character map in windows and all values are in the [0x00, 0xFF] range.

dvm
04-17-2005, 04:42 PM
Ouf, finally solved it. It wasn't an OpenGL or charset problem at all. It had to do with a small piece of code that would center the string in the window.

for (unsigned int loop=0;loop<(strlen(str));loop++) // find length of text
{
int tmp;
tmp = gmf[str[loop]].gmfCellIncX; // increase length by character's width
length += tmp;
}
glTranslatef(-length/2,0.0f,0.0f); // translate to center textAs it turns out, gmf's (of GLYPHMETRICSFLOAT fame) member gmfCellIncX contained wrong values for some of the letters, thus the function thought that a string was too long and translated way out.
For example the greek character 'alpha' has a gmfCellIncX width of 6642 units while 'beta' 2.1054e+008. Does anyone know if this is a programming error or a font error?