Jump to content
  • Advertisement
Sign in to follow this  
Sh@dow

OpenGL Get text length

This topic is 3091 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
I tried to use GetTextExtentPoint32 function. It returns wrong string dimensions.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!