View Full Version : get witdh of bitmap font problem :/

06-23-2004, 01:11 PM
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).

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!

06-23-2004, 07:00 PM
You're passing a pointer to NULL. Try it with an actual instance of ABCFLOAT.

int isOK=GetCharABCWidthsFloat(g_OGLwindow.hDC, 'a', 'a', &theABCF);This is more of a general programming/debugging problem than an OpenGL one, for your edification :-).

Make friends with your debugger and the MSDN library, they will help to save you considerable time and anguish.

06-23-2004, 10:53 PM
Hehe...I know I'm sorry to have posted it here. I'll pay more attention in the future.

Anyway, again, thank you a lot for your advice!