Displaying text in OpenGL. why so hard?

Started by
1 comment, last by Cornstalks 12 years, 4 months ago
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.
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).

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.


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)).
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

This topic is closed to new replies.

Advertisement