Bitmapped Font

Member
Posts: 86
Joined: 2008.04
Post: #1
I am displaying a bitmapped font like (psuedo code)

for each character in string
{
glDrawArrays( TriStrip );
}

is it better to do

for each character in string
{
build interleaved vertex/tex_coord array
}
glDrawArrays( Triangles );


The first appraoch calls glDrawArrays for each character, but each character only requires 4 verts.

The second appraoch calls glDrawArrays once for each string, but requires 6 verts for each character.

I know I could profile it - but I'm just looking for feedback before I take the time to implement - Thanks for any advice...
Quote this message in a reply
Member
Posts: 86
Joined: 2008.04
Post: #2
Well I went ahead and tried it out...

No fps difference when running in simulator and rendering hundreds of extra strings....

But on the 3gs, I get an 11fps improvement when running with a hundred extra strings rendered.

So I guess it definitely helps to batch and use GL_TRIANGLES even with the additional vertex count increase of 2 per character.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #3
Useful numbers. Thanks for sharing!
Quote this message in a reply
Member
Posts: 260
Joined: 2005.05
Post: #4
Speaking of bitmapped, or rather texture fonts, can you handle them as elegant in OpenGL ES as in OpenGL? I havn't had time to get serious with OpenGL ES so I havn't digged into this problem. I know all the things that are missing in ES. My texture font solution uses display lists (as most do) but last time I checked, display lists are not in ES. So how do you handle that? Iterate though the string manually, translating for every character? Or is there some other way that I am missing?
Quote this message in a reply
Member
Posts: 440
Joined: 2002.09
Post: #5
Ingemar Wrote:Iterate though the string manually, translating for every character?
Pretty much - you pack (or repack) characters into vertex arrays as needed.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #6
I dunno, I just do the exact same thing I did before using display lists, but use a call to glDrawArrays() with char*4 as the index and a separate translate call. I never generate any new vertex arrays. Only a few lines more code really.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 227
Joined: 2008.08
Post: #7
Hmm, this makes me wonder if my code is too slow/memory intensive Grin

For my font code (OpenGL 1.5):
In load font:
•Use SDL_ttf to put each char between 32-127 into a texture rect
•store width and height info of each char

In draw function:
•Start local x offset at 0
For each char in string:
•Bind texture of char in font
•Draw Quad with width and height info at x offset
•increment x by width info
Repeat until end of string

I imagine this is better than using Display lists (and I love display lists) in terms of memory, but that must be A LOT of vertex data sent down the pipes.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #8
The worst thing you are probably doing there is switching textures for each character. That gets to be pretty expensive when you are doing it hundreds of times per frame.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 260
Joined: 2005.05
Post: #9
Vertex arrays referring into one and the same texture is certainly doable, but you need a translation between every character. With a display list I draw a whole string with two lines of code. Essentially I do the same things I did when creating the display list. What disturbs me is that this feels like a step backwards, making the code more complicated and harder to optimize.

I think I will stick to my display lists until I need to change, e.g. when I want to support ES.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Anti-aliased bitmapped fonts Jake 12 6,326 Nov 19, 2007 05:02 PM
Last Post: Jake