[Bf-committers] Text Rendering

James sheepzilla at gmail.com
Fri Sep 19 12:16:48 CEST 2008


I've been hacking around with blenders text rendering for quite a long
time with the aim of improving the readability of the UI.
Specifically, I've been looking at using the true-type fonts that are
used for international text wherever possible, and using FreeType's
abilities for sub-pixel antialiasing and hinting to improve the ugly
way that these are rendered. (I'm aware of the potential patent issues
with using FreeType with these functions enabled, but I'm no expert on
the subject and since every linux distribution I've used recently
seems to use the library with them enabled, it seems sensible that it
should be possible to flip a switch when building blender so that
well-rendered text is displayed.)

To use subpixel hinting you have to know the background colour onto
which the text is going to be rendered - which is impossible most of
the time in blender without using expensive 2D read-back OpenGL
functions, so I've taken the approach of rendering a whole text string
to an RGBA buffer, applying a blurry background in the background
colour, and then rendering the result either as a texture or a 2D
pixmap.

With a bit of added caching this doesn't have much of a performance
hit, either, in fact it seems to improve pixmap text rendering
performance considerably, however rendering in texture mode (faster
still), I have a problem:

Once I've rendered a string of text, I keep the texture ID in a sort
of first-level cache in case it needs to be rendered again soon, but
of course as soon as I delete it from this cache and free the texture,
the text will disappear from the screen. I have no way to know when a
string ceases to be visible, so if its okay to remove it from the
cache!

Essentially, I can see two ways to solve this problem, either a
guarentee from the user interface that everything will be redrawn at
least once every, say, 30 seconds. Or some cheap OpenGL call that I've
never heard of that could tell me which textures are still in use.

I still have plenty of other creases to iron out in my code, but this
particular problem has been bugging me lately. I'd be really grateful
for any bright ideas.

Incidentally, on the platform I use most - OS X - when I run out of
texture memory bad, bad things happen, and generally I'm lucky if I
don't have to press the reset button. I guess its because the OS
interface is drawn using OpenGL, too.


Regards, James


-- 
sheep


More information about the Bf-committers mailing list