Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android OpenGL ES 2.0 text rendering

There seems to be a distinct lack of support on the web for how to display text in OpenGL ES 2.0. JVitela's answer at: Draw text in OpenGL ES says to use a Canvas, and Paint the Text on that to generate a bitmap, and then use GLUtils to render the text bitmap, but the answer only shows the part directly about painting the text, not what else goes around it.

I've also been trying to go off the lessons at http://www.learnopengles.com , in this case Lesson 4 which deals with basic Textures.

How is JVitela's method passed to a vertex or fragment shader? Is the section about the background necessary, or will leaving the background out result in just the text over the rest of the GL Surface? What exactly is the textures variable he used? I think it's a texture data handle (comparing his bind() to at that of learnopengles) but why an array? is it shared with other textures?

I have a programme with a heap of stuff displayed on it already with OpenGL ES 2.0, and need some basic text (some static, some updating every 1 to 5 Hz) printed over it. My understanding is that texture mapping bitmap glyphs is quite expensive.

Are there any good tutorials to do what I need? Any advice from anyone?

like image 483
eskimo9 Avatar asked May 10 '12 01:05

eskimo9


1 Answers

How is JVitela's method passed to a vertex or fragment shader?

It is passed like any other texture:

  1. Create a texture
  2. Set filtering and wrapping
  3. Upload data via GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

Is the section about the background necessary, or will leaving the background out result in just the text over the rest of the GL Surface?

It is not necessary (there will be just a background), leaving it out will write black pixels (because the code erases the bitmap pixels before with black. If you wanted to just draw the text, you'd need to enable blending or use a special shader that knows the color of the text.

What exactly is the textures variable he used?

It is an int[1], see API docs on GL10.

I think it's a texture data handle (comparing his bind() to at that of learnopengles) but why an array? is it shared with other textures?

This way, more than one texture handle can be created using glGenTextures.

like image 114
Stefan Hanke Avatar answered Oct 21 '22 06:10

Stefan Hanke