View Full Version : Length of Bitmap Font Strings
05-04-2004, 06:50 PM
I'm using the WGL routines to create a bitmap font in OpenGL. I'm trying to find a way to calculate the width in pixels of a string in a bitmap font. I've tried GetCharWidth32() and GetCharABCWidths(). Unless I'm using them incorrectly, they both consider "lllll" and "WWWWW" to be the same width even though I'm using a variable-width font. If someone could point me to a method by which I could accomplish this, I would be very grateful.
05-04-2004, 07:19 PM
Try this guy:
HDC hdc, // handle to device context
LPCTSTR lpString, // pointer to text string
int cbString, // number of characters in string
LPSIZE lpSize // pointer to structure for string size
But remember that any scaling you do on the gl matrix stack will affect the rendered text.
05-05-2004, 10:00 AM
I tried that as well. Same problem. Ideally, I'd like to be able to get the widths of all 256 characters and put them in an integer array, and use that array to calculate widths of strings. I've been able to do that with all three of these functions, but it's always used the same value for every entry.
05-05-2004, 01:51 PM
You need to make sure you have your font selected in th dc:
HFONT oldFont = (HFONT)SelectObject( hDC, myFont );
const char* text = "my dog has fleas";
GetTextExtentPoint32( hDC, text, strlen(text), &extent );
// now extent contains the width and height
SelectObject( hDC, oldFont );
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.