Advertisement

Render text in openGL

Started by August 12, 2012 01:49 PM
8 comments, last by gatofedorento 12 years, 3 months ago
Hey there.

I'm currently developing a GUI library from scratch, and after making the classes for buttons, windows, scrollbars etc I think its time to make them more user friendly by adding some text.

Today i tried to use the FTGL to draw some text, but the performance was very bad, just by drawing a window i got somewhat around 1300 fps, but if I drew it and a string ,with something like 20 characters, the framerate got around 200 fps using FTBitmapFont, it got even worse if I used FTPixmapFont.

I tried to use this library to avoid writting my own FreeType wrapper, basing myself on nehe's code that i saw here http://nehe.gamedev.net/tutorial/freetype_fonts_in_opengl/24001/ , though I think I could get a better performance from it.

Is there a better way to avoid these performance hits using FTGL?
Are there better text rendering APIs to use just to render some simple text on my GUI components? I don't really need anything complex, just some simple 2D text.

Cumpliments.
Does it drop even more if you draw lets say the screen full of text?

The cost of just drawing a window is so small that adding anything to it could multiply the time it takes to render a frame...

o3o

Advertisement
I will let you with two captions from my application, in the first one I have a window where I draw a button, one of my windows and a scroll bar, in the second one I draw the same components adding that "my text", and you can see the differences on the command line prompt in the left.

I think this was what you wanted me to show you...

http://i45.tinypic.com/2818owi.jpg
http://i50.tinypic.com/30ddt2p.jpg
No i meant does the fps drop more if you add more text.

like what happens if you display a string of lets say 100 characters?

and do you draw the string yourself or does the library do it for you?

o3o

With a string of somewhat 150 characters the framerate goes around 14 fps.

Its the library that draws it.
Random google search got me

"Getting rid of the "FaceSize" calls and using glScale instead resulted in a Framerate way above 100."

o3o

Advertisement
tried it and doesn't seem to change the font size, and if i don't even call "FaceSize" it doesn't even renders any text.

Thanks for help, maybe i need to dig a bit more the library, though, the tutorial isn't the best...
I believe the person who said that was calling it every frame or something. Try calling it once at the start...

o3o

The way I created an OpenGL FreeType Font is by basically creating a bitmap font from the TTF font. I would take all the glyphs and render the bitmap for each glyph and then put them all on one texture.

Then I would treat this font texture like a sprite sheet and render a sequence character sprites to render lines of text.

This managed to get me pretty good performance.

Learn to make games with my SDL 2 Tutorials

That's what i intend to do, by doing that the only performance hit my application will take is creating the textures,
though that ain't a real problem because they will usually only be created on an init function

thanks for help, I will try that tomorrow.

This topic is closed to new replies.

Advertisement