• Advertisement

Archived

This topic is now archived and is closed to further replies.

Faster Text?

This topic is 5975 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a faster way to display text other than using glCallLists? But also about as easy to implement? In my program, I'm getting 315 FPS without text, 105 with. It's a pretty substantial difference. Oh, and it's a simply 2D game so yeah, that's a lot of frames per second. =) Thanks, - Mike Edited by - mkaltner on September 11, 2001 3:29:47 AM

Share this post


Link to post
Share on other sites
Advertisement
hi there,

the fastest way is to use texture fonts rather than bitmap
fonts.

use 1 texture for your entire font ie 1x256x256 and just
calculate the position for your letters texture coordinates
in this way you only need to bind the texture once per
text output.

Hope it helps

Mark

Share this post


Link to post
Share on other sites
Well, I''m still pretty new to OpenGL so I woulnd''t know how to go about that. I can load and show a bitmap just fine but how would I do the coordinates of the letters to show? Could you give a little explaination of or even a code snippet?

Thanks,
- Mike

Share this post


Link to post
Share on other sites
Ok, it''s been a while since i did some code in openGL, so i leave the openGL part and just show you some code on how to get the appropriate coordinates on the texture.

First of all, create a bitmap containing the characters you want. I''d sudgest you choose the size 256x256 on the bitmap.
Now, make a grid of 16 pixels per grid on the bitmap.

This allows you to paint a character of 16x16 bytes, which should be enough. You also have room for 256 characters, which is the entire ASCII-list.

Now, give each grid with a index, like this:

0-15
16-31
32-47
48-63
and so on.


Now you just need to paint the appropriate characters in those grids.

For example, the number ''0'' has the ASCII value 48, which means the 4''th column and the first row. (See the example above)

Just fill in the blanks! find an ASCII definition table and paint the appropriate characters.

And now the code:

struct FRECT
{
float left;
float top;
float right;
float bottom;
};

void getcharposition(unsigned char character,FRECT *pos)
{
//define some variables
float row;
float column;

//Now we find out the position of the character.
row = character % 16;
column = character / 16;

//..And scale them to the range of 0.0f - 1.0f
row = 256/row;
column = 256/column;

pos->left = row;
pos->top = row;
pos->right = row+(16/256) // (16/256) scaled size of one grid.
pos->bottom = row+(16/256)
}



There! Now it''s just to omplement it!
(Could look something like this)

void glWriteTxt(FRECT *textposition,char *string)
{

glLoadTexture(GL_TEXTURE_2D,chartexture);
float num;
float charsizeinwindow = (textposition->right - textposition->left) / strlen(string);
FRECT charpos;
glBegin(GL_QUADS);
for (num = 0; num < strlen(string); num++)
{
getcharposition(string[num],&charpos);
glTexCoord2f(charpos.left);
glVertex3f(textposition->left+charsizewindow*num,textposition->top,0);
glTexCoord2f(charpos.right);
glVertex3f(textposition->left+charsizewindow*(num+1),textposition->top,0);
glTexCoord2f(charpos.right);
glVertex3f(textposition->left+charsizewindow*(num+1),textposition->bottom,0);
glTexCoord2f(charpos.left);
glVertex3f(textposition->left+charsizewindow*num,textposition->bottom,0);

}
glEnd();

}


That should do it...

Share this post


Link to post
Share on other sites

  • Advertisement