Hi all…
I want to get the width of a bitmap font character. Ultimately I want to be able to know the width of a string so I can center it when printing.
I use this code from NeHe as a basis:
GLvoid CFonts::glPrintBM(const char *fmt, ...) // Custom GL "Print" Routine
{
char text[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments
if (fmt == NULL) // If There's No Text
return; // Do Nothing
va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap); // Results Are Stored In Text
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(baseBM - 32); // Sets The Base Character to 32
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text
glPopAttrib(); // Pops The Display List Bits
}
In another post on this forum I found something useful about GetCharABCWidthsFloat, but I can’t get it to work (I’m pretty new). The compiler says ‘theABCF’ is not initialized and the exe crashes if I run it. If I do theABCF = 0 then I get the same (also a crash).
LPABCFLOAT theABCF;
int isOK=GetCharABCWidthsFloat(g_OGLwindow.hDC, 'a', 'a', theABCF);
glRasterPos2f(20.0f, 50.0f);
g_font.glPrintBM("=%f %f %f", theABCF->abcfA, theABCF->abcfB, theABCF->abcfC);
What should I do to get things running?
Thanks a lot for helping me!