6

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?

Community
  • 1
  • 1
eskimo9
  • 753
  • 10
  • 24

1 Answers1

2

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.

Stefan Hanke
  • 3,458
  • 2
  • 30
  • 34
  • "leaving it out will write black pixels" Meaning it will overwrite everything else on the screen? or will place a black box around the text? Not sure what you mean here. – eskimo9 May 10 '12 at 06:03
  • "everything else on the screen" - the texture is applied to a quad, so it overwrites everything behind the quad (provided that depth test succeeds, and there is no blending). There is no notion of "around the text" - there is a Canvas which is painted over. – Stefan Hanke May 10 '12 at 06:12
  • OK I can get it to draw text over a background image, but it renders the texture onto all of my visible objects. I must be setting up the texture in the wrong place. Do you know of a good beginner tutorial to applying different textures to different surfaces? – eskimo9 May 11 '12 at 06:34
  • Not for this special problem. You need to have an `Entity` class or something similar that can be assigned a texture somehow (A `Texture` object or directly the OpenGL handle). Then, when drawing one particular `Entity` instance, bind the given texture first before drawing. Afterwards, disable texturing completely, or unbind the texture via `glBindTexture(, 0)`. See [here](http://www.arcsynthesis.org/gltut/Texturing/Texturing.html) for details. – Stefan Hanke May 11 '12 at 08:37