Get text length

Started by
4 comments, last by szecs 13 years, 11 months ago
Hi everyone. I'm using OpenGL to draw text on the screen.The font was created with CreateFont function.(NeHe lesson,bitmap fonts).In order to position the text i need to know it's length. How can't i retreive it in pixels or in screen dimensions? Thanks in advance.
Advertisement
Not sure exactly how OpenGL fonts work, but if they draw text the same way as GDI, you can use SelectObject to select the font into your HDC, and then GetTextExtentPoint32 to calculate the width of the string.
Quote:Original post by Erik Rufelt
Not sure exactly how OpenGL fonts work, but if they draw text the same way as GDI, you can use SelectObject to select the font into your HDC, and then GetTextExtentPoint32 to calculate the width of the string.
Yep, openGL works this way.
Quote:Original post by szecs
Quote:Original post by Erik Rufelt
Not sure exactly how OpenGL fonts work, but if they draw text the same way as GDI, you can use SelectObject to select the font into your HDC, and then GetTextExtentPoint32 to calculate the width of the string.
Yep, openGL works this way.


It doesn't really, OpenGL doesn't have any form of font rendering.
CreateFont is a Windows function, not an OpenGL one. (it is a part of GDI) and wglUseFontBitmaps is a Windows OpenGL extension (not portable).
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
I tried to use GetTextExtentPoint32 function. It returns wrong string dimensions.
You have to set the font you use with SelectObject. In the Nehe tutorial, the init switches back to the default font immediately. Delete that line, and set back to default only in KillFont.

Anyways, this can be used to render fonts in openGL. There are other methods too of course.

This topic is closed to new replies.

Advertisement