Jump to content

  • Log In with Google      Sign In   
  • Create Account


Faster Text?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 mkaltner   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 September 2001 - 08:14 PM

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

Sponsor:

#2 MButchers   Members   -  Reputation: 123

Like
Likes
Like

Posted 11 September 2001 - 12:38 AM

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

#3 mkaltner   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 September 2001 - 06:55 AM

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

#4 Electron   Members   -  Reputation: 122

Like
Likes
Like

Posted 14 September 2001 - 11:29 AM

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...






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS