How can I get the Fontwidth in pixel of a font I created.
Here’s the code where I create the font:
UINT CreateOpenGLFont(LPSTR strFontName, int height)
UINT fontListID = 0;
fontListID = glGenLists(MAX_CHARS);
hFont = CreateFont( height,
0, // The WIDTH (If we leave this zero it will pick the best width depending on the height)
hOldFont = (HFONT)SelectObject(g_window->hDC, hFont);
wglUseFontBitmaps(g_window->hDC, 0, MAX_CHARS - 1, fontListID);
How can I get the font width?
That is a bit tricky, the rasterposition is advanced when you draw a character so you can use that to calculate the width, but this requires a glGet call, not the best solution.
Another solution is to use freetype instead, this also gives you platform independence, if you want that, there are some very nice libraris that use freetype to draw text using OpenGL with all kinds of neat features.
I use “Arial” because the other fonts takes to much space.
Maybe I can store the width of every char in an array. But I don’t know how to use glGet
Look it up on http://msdn.microsoft.com
Mentions something about GLYPHMETRICS, so you might be able to use GetGlyphOutlines or GetTextMetrics. Maybe.
Ahum,guys!It seems that you’ve forgotten one the most used Win32 functions.Yep this is “GetCharWidth”.Take a look at the MSDN for it and check what does it do