Plz help. How to draw text in OpenGL Es 2.0?

Hello,
I am new in OpenGL ES 2.0 and I am trying to draw a text but I have no idea how to do. Can anyone tell me how to do it or any tutorials ? Thanks for any replies.

There is no API in OpenGL (or OpenGLES) for drawing text. You either do that outside of the API (maybe using some other operating-system commands) - or you write your own font rendering stuff.
One simple way to do that is to make up a short/wide texture map with all of the ASCII characters in it - then write code to draw each letter as a textured quadrilateral using the appropriate texture coordinates to extract the right letter out of the texture map.

If you have a lot of text - that might mean drawing a LOT of polygons. Another approach (if your text is relatively fixed) is to store entire words, phrases or even sentences as texture and draw the whole thing with one textured quad.

A very long time ago, I wrote a FAQ about this (that was back in the era of OpenGL 1.2!)

  [http://www.sjbaker.org/steve/omniv/opengl_text.html](http://www.sjbaker.org/steve/omniv/opengl_text.html)

On systems with decent shader support, I’ve been experimenting with a technique where I send the strings I need down to the GPU as a texture map with one texel per character (containing the ASCII code) and use fragment shader code to convert use that value as the coordinate for looking up the font texture - amazingly, it actually works pretty well. For text that only changes slowly (so you aren’t continually reloading the texture) that can be blindingly efficient. However, the shader to do that is a pain to get right!

– Steve

Thanks 4 ur reply!!! :slight_smile:

As an extension to this, i recently setup a simple text renderer porting NeHe’s excellent Freetype tutorial (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=43) over to run on iOS. At its most basic, it extracts bitmap glyphs using the freetype api, expands them to 2^n textures suitable for OpenGL and stores the quad coordinates/ texture coordinates. To render, you iterate through a string and draw the textured quad translating along by the width of the previous letter.

As has been said, if you have allot of text this method creates a 2 triangles per glyph so where possible, consider rendering full text strings as textures in their own right.

Hello BKB,

I know I am a year late, but I have went to the nehe link you had in your reply and I couldn’t find your iOS version of text rendering with freetype api. Can you please direct me where to get it from?

Thank you !

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.