Get text length
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.
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 RufeltYep, openGL works this way.
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 szecsQuote:Original post by Erik RufeltYep, openGL works this way.
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.
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).
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.
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
Popular Topics
Advertisement