Post by Andrea B. PreviteraI'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:
double negStrWidth;
GLdouble tmpCurrentRasterPosition[4];
CString strText = _T("TEST");
glGetDoublev(GL_CURRENT_RASTER_POSITION, tmpCurrentRasterPosition);
negStrWidth = tmpCurrentRasterPosition[0];
glCallLists(strText.GetLength(), GL_UNSIGNED_BYTE, strText);
glGetDoublev(GL_CURRENT_RASTER_POSITION, tmpCurrentRasterPosition);
negStrWidth -= tmpCurrentRasterPosition[0];
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
http://home.arcor.de/kotyczka/opengl_en.html.
Feel free to send me an email for further questions.