[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ft-devel] [ANN] Freetype/OpenGL (with good rendering quality)

From: Nicolas Rougier
Subject: Re: [ft-devel] [ANN] Freetype/OpenGL (with good rendering quality)
Date: Wed, 21 Sep 2011 18:51:01 +0200

Thanks for the tips, I'll give it a try. One problem is that glyphs are loaded on demand and consequently I do not have full control.

The subpixel positionning is made using a shader. I display the glyph at a given integer coordinate and send along the float component:

If glyph must be displayed at coordinate x=5.4, I display it at x=5 and send m=.4 to the shader. Then depending on m ( 0-.33, .33-.66 and .66-.99), I make a combination with previous pixel for each color channel:

    // current pixel as r,g,b,a
    vec4 current = texture2D(texture, uv);

    // prevous pixel as r,g,b,a  
    vec4 previous= texture2D(texture, uv+vec2(-1,0)*pixel);

    float r = current.r;
    float g = current.g;
    float b = current.b;
    float a = current.a;
    if( m <= 0.333 )
        float z = m/0.333;
        r = mix(current.r, previous.b, z);
        g = mix(current.g, current.r,  z);
        b = mix(current.b, current.g,  z);
    else if( m <= 0.666 )
        float z = (m-0.33)/0.333;
        r = mix(previous.b, previous.g, z);
        g = mix(current.r,  previous.b, z);
        b = mix(current.g,  current.r,  z);
   else if( m < 1.0 )
        float z = (m-0.66)/0.334;
        r = mix(previous.g, previous.r, z);
        g = mix(previous.b, previous.g, z);
        b = mix(current.r,  previous.b, z);

Final color is then r, g, b, a.
I compared with direct freetype rendering but obtained small differences.


On Sep 21, 2011, at 18:07 , Alexei Podtelezhnikov wrote:

I think you can pack the bin better if you start from the largest
size. There is tons of empty space at the bottom that could easily be
filled with small glyphs. Or go bottom-up for more natural fill. In
other words, I bet you can pack more glyphs into 512x512.

I am not sure I understood how you do subpixel positioning from the texture.

On Wed, Sep 21, 2011 at 6:55 AM, Nicolas Rougier
<address@hidden> wrote:

Hi Folks,
You might be interested in the following code that allow to render freetype
font using OpenGL with quite good quality (IMHO):

There are examples for "infinite" zoom, subpixel positioning, gamma
I got most ideas from the antigrain library:
(the "demo-atg-agg.c" tries to reproduce the truetype_test from this

Freetype-devel mailing list

Alexei A. Podtelezhnikov, PhD

reply via email to

[Prev in Thread] Current Thread [Next in Thread]