开发者

Measure Bitmap Fonts with OpenGL (Windows)

What is the 'correc开发者_如何学运维t' way to determine the 'pixel' length of bitmap fonts rendered in OpenGL? I'm using 2D ortho and the wglUseFontBitmaps() function to build font character lists in Windows. If I want to measure the size of my resultant text (for centering, formatting etc), what is the correct way to do this?

Should I be using the Win32 GDI GetTextExtent() API function, or is there a means of determining the current 'cursor' position within OpenGL? The glRasterPos functions sets the output position, and as each character is rendered, the output position automatically advances.. so is there a glGetRasterPos perhaps that I could use?


OpenGL doesn't own the fonts; Windows GDI must provide the information. I showed how to do it right in my answer to this question. You need GetCharABCWidths() for the per-character widths and GetTextMetrics() for the heights. Look at my for loop over formattedString.GetLength(), which calculates the string width in pixels. Then you can use glRasterPos2d() to put the text in the right place.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜