Jump to content
  • Advertisement
Sign in to follow this  
FantasyVI

OpenGL Displaying text in OpenGL. why so hard?

This topic is 2575 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

Hello everyone
so a month ago i started learning OpenGL and not till today that i had to display some text in OpenGL and to my surprise its hard !!
why is it so hard to display text in OpenGL ? why couldn't it be as simple as ( std::cout<<"Text"; ) ?
i did my research i found a lot of way to display text but I'm not sure which one to use. i found bitmap text - texture text - draw text as lines or just use freetype which i found very hard to understand for some reason.
which one should i use? i read somewhere that bitmap text is slow and send a lot of data to the GPU which slows things down. I just want to load fonts change text color and display simple text. nothing fancy i don't want the text to rotate or display it in 3D just old fashion 2D text.

also how can you display text like in old RPG's ? for example display each letter at a time.


also i used SFML and the way they handle text is very nice and clean as far as i know and i think they use freetype library to do so.

Share this post


Link to post
Share on other sites
Advertisement
Displaying text is indeed quite hard with OpenGL. I wouldn't use lines, I'd either go for the texture (you put all letters on a image and draw bits of it around the place) or Freetype. I've not tried freetype, it may be hard to understand but the texture bit is alot of work. A long time ago I used this: http://students.cs.byu.edu/~bfish/glfont.php it worked well. Its the texture type implementation.

Displaying text slowly like you have shouldn't be too difficult. You have 2 strings, one is the text in its entirety, the other is the part your actually showing. Every so often (miliseconds/ticks, whatever time your game uses) you add a little more to the displayed text (substring).

Share this post


Link to post
Share on other sites

why is it so hard to display text in OpenGL ? why couldn't it be as simple as ( std::cout<<"Text"; ) ?


It's hard because that doesn't answer all the questions the graphics library would have: where to draw the text? What size? What color? What rotation? Any kind of special effects, like gradients, transforms, etc? What font? Those are just the beginning questions.

Personally, I used Freetype and I really liked it. It's a little bit difficult to get it set up your first time, but once you've got it working you can just write a wrapper class and use it pretty easily. When I did it I used Freetype to generate the images for each character I'd be using in the game (A-z, 0-9, all the punctuation characters, etc) and then used this to pack the images into a single texture. Then when rendering text, I just drew quads that used only a portion of the font-texture (note that using different font sizes required me to generate a new font-texture (that is, if I wanted it to be pixel perfect, otherwise you can get away without it)).

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!