Java – Android opengl drawing text

Android opengl drawing text… here is a solution to the problem.

Android opengl drawing text

I’m planning to draw text using opengl but can’t figure out how to get it to draw/build the actual string. If I wanted to draw “Hello World”, I could create a texture for each letter and draw them all, but I knew there had to be an easier way to “pull” the correct character set at once and then draw only once. I guess I could take all the individual textures, add them to an array of vertices, and then call draw only once to paint the array of vertices, but that doesn’t seem efficient. Is there a tutorial that covers this specific section?

Solution

Suppose you only want 2D letters to appear at a certain point in 3D space, the normal way to do this is the one you described. I actually create a bitmap for the entire string and then draw that bitmap into the scene. It’s not really inefficient – in fact it’s very efficient because you can cache bitmaps of text and only need to calculate it once instead of every time you draw the scene. There is a lot of seemingly simple code, but OpenGL usually does.

Related Problems and Solutions