Drawing text in OpenGL

Discussion in 'iOS Programming' started by BananaDuffle, May 20, 2009.

  1. BananaDuffle macrumors member

    Joined:
    Mar 29, 2009
    #1
    If I'm drawing text in OpenGL from a texture (png grid of numbers and letters) what's the best method of achieving this?

    I'm conscious of minimizing draw calls so I'm trying not to draw a textured "quad"(albeit as a tri fan or tri strip) for each letter... is this correct.

    Is there an approach i can employ to render all my text in a single draw call?
     
  2. lazydog macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #2
    Hi

    I'm drawing text as textured quads... well I figured this was the most flexible as it gives you the ability to rotate, size and colour the text easily.

    ß e n
     
  3. BananaDuffle thread starter macrumors member

    Joined:
    Mar 29, 2009
    #3
    Are you drawing one textured quad per letter with one draw call per quad?

    I was hoping to make a triangle-strip and use different texutre co-ords per 2 triangles, so as to write out a word... but triangle strips only have one texture coord per vertex so that kept messing up (i.e the second letter shared 2 texture co-ords with the first, so unless the letters I was drawing where next to each other on the sprite sheet it got messed up). And OpenGLES is missing a GL_QUADS for its draw array so I was left scratching my head as the only other option was to pre generate all my text as a single texture per block of text or use a bitmap font sheet and make one draw call per letter which sounds like a massive performance drain just to render text.
     
  4. lazydog macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #4
    Hi

    Yup, I'm drawing a triangle strip with 2 triangles per letter, but then that happens to suit what I'm doing well. Sounds excessive but what the heck! I guess if your text is 'static' then there would be better ways. In OpenGL, ie not ES, there are other ways of doing text, eg glBitmap(), but I don't think there are equivalent ways in ES.

    I'm writing a tool that dumps out fonts as a single alpha texture. If you think it might be of use to you I'd be happy to send it to you when it's finished.

    ß e n
     
  5. kalimba macrumors regular

    Joined:
    Jun 10, 2008
    #5
    I'm trying to build the same thing right now. I thought that a triangle strip would be the most efficient, but on closer examination I found the same thing you've just posted: since a tri-strip has some verts that are shared between two adjacent characters, it's impossible to specify a single texture uv for that vert, since the uv for the first character would rarely (if ever) be the same uv for the adjacent character.

    So, that leaves either (a) batches of small (2-triangle) tri-strips, one for each character, or (b) one single batch of "plain" (non tri-strip, non-tri-fan) triangles.

    Anyone know which of these would be more performant? I suspect approach (b) would be more efficient, but I'm not at the point of being able to test this yet.
     
  6. lazydog macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #6
    Don't know if this of any use but I think you can use a triangle strip with degenerate triangles. So between each character you would create two zero area triangles. This will let you fix up the uv coordinates.

    b e n
     

Share This Page