Archived

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

Fast fonts

This topic is 5532 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

I''m currently using NeHe''s bitmapped font tutorial to render text to the screen but it''s painfully slow. My project runs at 60fps on a ~400Mhz laptop with an 8MB card but drops to 14FPS when text is drawn. I was wondering if there''s a better font class out there or if I''m just going to have to write my own. It needs to at least be able to recognize a ''\n'' although word wrap already put in would be nice. Ben IcarusIndie.com [ The Rabbit Hole | The Labyrinth | DevZone | Gang Wars | The Wall | Hosting | Tiberian Merchandise!!!! | GameShot ]

Share this post


Link to post
Share on other sites
There''s a simple solution to this: stay away from bitmapped fonts at every opportunity. They''re not optimized, and can seriously degrade your high framerates.

There are loads of tutorials out there (even one on NeHe''s site) which deal with texture-mapped quads as a means of creating text. Basically you create a 256x256 texture, and fill it with all the letters and punctuation. Then, you load it in, and create display lists for every character. When you want to draw text, you write an algorithm that runs through the text string character by character, and calls the appropriate list for that character.

As you''re drawing textured quads, they''re hardware accelerated, and much, much faster than bitmapped fonts...


Movie Quote of the Week:

"You''ve been eating retard sandwiches again."
- Birdman, Beautiful Girls.
Try http://uk.geocities.com/mentalmantle. Seriously. It''s brilliant.
And I just completely redesigned it so it looks even better.
DarkVertex Beta 0.8 available soon!

Share this post


Link to post
Share on other sites
"google has some good stuff on fast(er) gl fonts."

thanks n00b

"Basically you create a 256x256 texture, and fill it with all the letters and punctuation"

Yeah, I used that method for Gang Wars, Tombstone and Gravity Kills. However, I want the user to beable to specify the font name and size in the ini file for this project.

This project also has a DX 8.1 version which uses fonts and manages to drop only 11FPS with a long line of text while OpenGL drops 70FPS with the same line of text.

Basically what the DX 8.1 font class does is automatically create the offscreen surface and puts the fonts to them and then stores the vertice information. I''ll probably just have to port that function over to my OpenGL class.

Ben


IcarusIndie.com [ The Rabbit Hole | The Labyrinth | DevZone | Gang Wars | The Wall | Hosting | Tiberian Merchandise!!!! | GameShot ]

Share this post


Link to post
Share on other sites
quote:
Original post by KalvinB
thanks n00b


you''re welcome. i see that you''d rather spend days waiting here for someone to hand a solution to you than spend half an hour searching for it yourself. grow up.

Share this post


Link to post
Share on other sites
"Fonts from textures are goooooood!"

font on a texture

Yep. I managed to create a function which would write all the characters of any font of any size to an OpenGL texture. Unfortunatly it only worked in a 1024x768 because of scaling and offsetting that had to take place. Also, the vertices were dependent on the font and so they couldn't be automatically generated. I had to do translations which didn't go over well when trying to store them in the vertices.

So I'm now writting them to the HDC and they show up just like they're supposed to so the vertices are being stored correctly but now I need to go from the HDC to the OpenGL texture.

How do I go about doing that?

BitBlt is I guess the function for doing it because I have no idea how to reference the texture by an HDC handle so I can copy to it.

Ben


IcarusIndie.com [ The Rabbit Hole | The Labyrinth | DevZone | Gang Wars | The Wall | Hosting | Tiberian Merchandise!!!! | GameShot ]


[edited by - KalvinB on October 19, 2002 7:30:58 PM]

Share this post


Link to post
Share on other sites
"Will build the texture for you from two True Type fonts. The program also allows you to export font width information to a file to let you import character information into your application."

Building the fonts is easy as the screenshot I posted demonstrates I''ve already accomplished.

Your app doesn''t help because the whole point of what I''m trying to do is to allow the End User to choose any font they want of any size by changing a couple variable in an ini file. Having a predrawn bitmap defeats the entire purpose. The DirectX version of my app does exactly what I''m trying to get OpenGL to do.

How do I go from the HBITMAP with the fonts drawn on it to an OpenGL surface? Besides by saving it at a bitmap and then loading it.

Ben


IcarusIndie.com [ The Rabbit Hole | The Labyrinth | DevZone | Gang Wars | The Wall | Hosting | Tiberian Merchandise!!!! | GameShot ]

Share this post


Link to post
Share on other sites
Got it. I just had to GetPixel over the part of the HDC I wanted and then convert the resulting values to bytes and put them into the data array for the texture.

This is an amazingly bad way of doing it but it works. Now for my next trick I''ll do all this off screen so you don''t see the font bitmap on load.

Ben


IcarusIndie.com [ The Rabbit Hole | The Labyrinth | DevZone | Gang Wars | The Wall | Hosting | Tiberian Merchandise!!!! | GameShot ]

Share this post


Link to post
Share on other sites
Glad you got your trouble figured out, Ben - here''s another way you could do that though. Instead of using GetPixel from the HDC, you could build your HDC, draw your text to it, and then use the GetBitmapBits call.

Example: In the fire screensaver I released on my page, there''s a clock mode where you see some flaming numbers flying around. To generate the bitmap font, I simply used GetBitmapBits(clockBitmap, 60*33*2, clockBitmapBits) after drawing the font to the clockBitmap HBITMAP by selecting the clockBitmap into a DC. Hope this gives you a boost in the right direction.

Share this post


Link to post
Share on other sites