Results 1 to 4 of 4

Thread: Font rendering acceleration in v0.9

  1. #1

    Question Font rendering acceleration in v0.9

    I'm using ClanLib v0.9 on the Windows platform, trying to render some status texts for my game with CL_Font and CL_GraphicContext::draw_text().

    Unfortunately this method is way too slow to be called every frame (4 calls to draw_text() with short strings already drop my framerate from ~2200 fps to ~400 fps).

    I'm using a workaround that involves rendering the text to the offscreen framebuffer with CL_GraphicContext::draw_text(), than copy it into a texture with CL_Texture::copy_image_from().
    If text has not changed since the last frame, display the texture immediately, otherwise repeat the first steps, than display the texture.

    That kinda works but it feels there should be a more straightforward way to do this.
    v0.8 had bitmap fonts which should render faster - are there any plans to port bitmap fonts to v0.9?

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Are you using the latest SVN (from less than 5 days ago - if i remember correctly)?

    0.9 Font has recently been optimized (There has a problem with font caching)

    It caches the font glyphs as CL_PixelBuffer's, so it should work very fast.

    Indirectly 0.9 also has bitmap fonts, by using gc.set_font_glyph() (See Tests/GUI/GUIFont).

    If you are only using a limited number of glyphs, it may be preferable to store them as CL_TextureGroup (using gc.get_font_glyph()). See Tests/Display/Font2/texture_font.cpp

    Humm, Tests/GUI/GUIFont is not working....
    Last edited by rombust; 01-21-2008 at 01:11 PM.

  3. #3
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    The current system fonts implementation caches glyphs in CL_PixelBuffer objects. It then basically does a gc.draw_pixels(x,y,glyph_pixelbuffer) for each character. The optimization rombust refers to changed how it finds the pixelbuffer for the glyph, leaving the main speed decrease to CL_GraphicContext::draw_pixels.

    Unfortunately making draw_text faster from this point forward begins to get tricky.

    The options are:

    • Move the glyphs from system memory into video memory. OpenGL 2.1 allows you to do this by creating a buffer object and binding it before calls to glDrawPixels. Unfortunately creating a buffer object for each glyph will most likely be a bad idea, so logic required to store many pixelbuffers in the same buffer object would be required. Also, OpenGL has no functions for batching glDrawPixels calls, which means we would still need one call for every glyph.
    • Move the glyphs from system memory in textures. This is the approach ClanLib 0.8 uses, but once again you need the right glyph packing logic required. Theoretically CL_Sprite could be used, like CL 0.8 does. But unlike 0.8 the glyphs are generated on demand in 0.9, which would require CL_Sprite to be improved, or it to do its own housekeeping using CL_Texture objects.


    Both those requires enough work for us not to have bothered yet - the GUI has simply had higher priority than raw clanDisplay performance so far.

    That said, the fastest graphics is the graphics you don't do, which is exactly the plan of the GUI when it comes to games. In 0.8 our GUI would render itself every frame, but 0.9 instead caches it in textures so only changing components will affect performance. Although not all text is static, if you are seeking performance, it is probably a good idea to attempt to cache as much of it as possible in textures. If you take the chat window in World of Warcraft as an example, I would attempt to make it only render one new line of text as it arrives - never the entire chat window text.

    Of course it would be nice if ClanLib had some 2D helper classes letting you do this easilly..

  4. #4
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    CL_BitmapFont now exists in 0.9 (subject to change of course!)

    It stores the glyphs in a CL_TextureGroup

    To use, change CL_Font myfont(...) to CL_BitmapFont myfont(...)
    .. gc.set_font(myfont)

Similar Threads

  1. No hardware acceleration available.
    By sunnyplain in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 01-18-2008, 10:17 AM
  2. Font loading and the characters
    By Anvilfolk in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 09-14-2007, 05:08 PM
  3. I need help using CL_Font with a System font on the Mac
    By eoliveri in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 08-07-2007, 01:59 PM
  4. Rendering into my custom image and then drawing this image to the display
    By ValkaVALES in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 07-03-2007, 09:53 AM
  5. OpenGL acceleration
    By IvaN in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 02-11-2007, 06:14 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •