Results 1 to 5 of 5

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

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    3

    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.

  2. #2
    Senior Member
    Join Date
    May 2010
    Posts
    207

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

    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

    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

  3. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    3

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

    Thanks 4 ur reply!!! ^_^

  4. #4
    Junior Member
    Join Date
    Apr 2011
    Posts
    4

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

    As an extension to this, i recently setup a simple text renderer porting NeHe's excellent Freetype tutorial (http://nehe.gamedev.net/data/lessons....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.

  5. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    1

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

    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 !

Similar Threads

  1. OpenGL text rendering
    By sdivya in forum OpenGL ES general technical discussions
    Replies: 1
    Last Post: 06-17-2012, 10:37 PM
  2. draw text in OpenGL ES 2X
    By bobo77 in forum OpenGL ES 2X - for programmable 3D graphics pipelines
    Replies: 0
    Last Post: 10-02-2011, 09:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •