Best way to render text

Started by Cornix, July 20, 2013, 19:19:14

Previous topic - Next topic

Cornix

Hi.

I would like to hear your opinions on which way to render text is better.
I am currently looking at two alternatives:
1). For every text I create a new VBO. The VBO holds the vertex data for all characters in the text. I render the text by calling glDrawElements and drawing the entire text at once.
I guess this is faster in terms of performance, but it is costly when creating the text. And each time I want to change the text I have to delete the VBO and create a new VBO and upload it to the graphics card.

2). I have one VBO which stores the vertex data for all characters in my font. When drawing a text I loop through all characters in the text, find the index for the character in the VBO, call glTranslate to set the position for the character and then glDrawElements.
This results in one call for glDrawElements per character in the text.
This is obviously slower then the first alternative, but it would require just one VBO for all texts in the entire application.

Edit: 3rd alternative:
I have one VBO for all characters in the font. Each time I create a new text I create a new index VBO also. This way the render performance would still be as good as before and creating a new text would not be that demanding. I think this is the middle of the road.

What would you say is the better way?
Or is there a solution I havent thought about yet?

Thank you all for the help.

Morin

Your first method of drawing text is probably near the best for static (seldom-changing) text. You could probably improve on that using shaders (one vertex per character, generating the other three as well as texture coordinates using a geometry shader). Alternatively, you could use glTexGen to at least generate texture coordinates even without a shader. Your third solution will probably yield similar results and you don't have to fiddle with geom shaders.

Your second method is, judging by feeling, probably very slow. Any change to the transformation is probably much more expensive than passing a few vertices, because there's matrix multiplication involved (even though that is probably heavily optimized for special matrices like transformation), and might interfere with pipelined (parallel) processing, whereas vertices are just fed into the pipeline (and possibly multiple parallel pipelines).

Other than that, I just wrote a text rendering routine using old-fashioned glBegin/glVertex/glEnd, but then I'm not (yet) programming for OpenGL ES. For that, you'd probably have to use a VBO but could mark it for streaming usage. Also, glTexGen might work for either of those methods. I haven't tried that yet because text rendering just wasn't anywhere near being a performance bottleneck for me.

Keep in mind that even "fast-changing" text is slow-changing by OpenGL measure, otherwise the user would not be able to read it ;)

laserlars

I can't say it's the best way to render text but I just prepare the vertices and texcoords on the cpu in world space when I render my text. I don't keep anything in VBO for now. I'm not sure it would help much to have stuff in a VBO.

Also be aware that you could probably go to a smaller data type. Half floats or shorts. Even maybe doing some nice packing tricks and to keep the data even smaller.

I also end up with having just one draw call.

Also with my bitmap caching I switch glyphs so then I would have to keep track of that as well.