Post by Andrea B. Previtera
I've always used WglUseFontBitmap to create and output 2d text in my
opengl apps. The alternative would be using bitmapped fonts, which anyway
would limit me to *monospaced* fonts. Nonetheless, the problem with
WglUseFontBitmap driven text, is that for some reason I can't really find a
way to get the outputted string width in pixels...
No need to drop wglUseFontBitmap!
It is possible to get the string length in pixels.
It goes like this:
CString strText = _T("TEST");
negStrWidth = tmpCurrentRasterPosition;
glCallLists(strText.GetLength(), GL_UNSIGNED_BYTE, strText);
negStrWidth -= tmpCurrentRasterPosition;
If you need to calculate the string width before actually
rendering it you can first render it invisible [using a stencil
buffer if availible or by glDrawBuffer(GL_NONE)].
For details you might want to take a look at my demo
Feel free to send me an email for further questions.