Android opengl drawing text
I was planning on drawing text with opengl and couldn't figure out how I would get it to draw/build the actually string. If I wanted to draw "Hello World", I can create a texture for each letter and draw them all but I know there's got to be an easier way of "pulling" out the correct set of characters all at once and then drawing just once. I figured I could get all the separate textures, add them into a vertex array, and then draw the vertex array with only one call to draw, but that seems inefficient. Any tutorials that cover this particula开发者_如何学编程r section?
Assuming that you want just the 2D letters to appear at a certain point in 3D space, the normal way to do this is the one you describe. Well actually I would create a single bitmap for the entire string and then draw the bitmap into the scene. It's not really inefficient - in fact it's very efficient, because you can cache the bitmap of the text, and only have to calculate it once instead of each time the scene is drawn. It seems like a lot of code for something simple, but OpenGL is often like that.
I'm written an Android loader and renderer for my Bitmap Font Generator (CBFG) that does what you are talking about.
Android source to load and display the fonts is at http://www.codehead.co.uk/cbfg/TexFont.java
The tool to create your own the font files is at http://www.codehead.co.uk/cbfg
Basically, all the font glyphs are arranged on a single bitmap and the letters are drawn by rendering a series of identical quads changing the UV coords each time to display the required letter.
Hope that helps.
精彩评论