<p>From looking at your example images this looks like a case of Alpha blending being applied to the RGB channel of the font-atlas texture and then again applied via the A channel when rendering. </p>

<p>The tell-tale sign of this is usually a feint dark halo surrounding your glyphs which is caused by the unwanted mid-greys present in the texture being multiplied by alpha.</p>

<p>For font rendering it is typical to have anti-aliasing in the A channel and have your RGB channels a constant colour. </p>

CC BY-SA 3.0
2017-12-20T04:19:18.693Z
2017-12-20T04:19:18.693Z
PaulHK
<p>I'm rendering fonts using Cairo to surfaces, convert those surfaces to RGBA textures and then display them on GL_QUADS using orthotogonal projection and alpha blending. When I use Cairo to render directly to the window (i.e., without hardware acceleration), fonts look perfect. When I show them through OpenGL, they look "thinned". Example: <a href="https://i.sstatic.net/DkPbP.jpg" rel="nofollow noreferrer">https://i.sstatic.net/DkPbP.jpg</a></p>

<p>My texture sizes are powers of two and I do not currently use any scaling (i.e., use the texture coordinates to only show the portion of the texture that actually contains data). I've also tried using the full texture and scaling in the Cairo drawing matrix (i.e., upscaling by Cairo, downloading by OpenGL) which looks even worse.</p>

<p>I believe this has something to do with GL's interpolation, but cannot seem to figure out why it is. When I disable the bilinear GL_LINEAR texture interpolation to GL_NEAREST, they look even worse (and blocky, as if it'd ignore the alpha channel). What can I do to make my font textures look more true to their original?</p>

CC BY-SA 3.0
2017-12-18T10:51:22.750Z
is your lighting turned on for rendering? if so, i suggest trying to turn it off
Tare
CC BY-SA 3.0
2017-12-18T10:59:21.103Z
No, not using any lighting.
Jonas Mechtheim
CC BY-SA 3.0
2017-12-18T11:20:55.923Z
What kind of alpha blending are you using?
Dan Hulme
CC BY-SA 3.0
2017-12-18T11:21:53.513Z
I use glEnable(GL_ALPHA_TEST) and glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) at the initialization of my program.
Jonas Mechtheim
CC BY-SA 3.0
2017-12-18T11:48:25.007Z
Is the RGB channel of the font texture all the same colour? It should not contain any anti-aliasing in the RGB channel, only the A channel.
PaulHK
CC BY-SA 3.0
2017-12-18T12:38:35.103Z
@PaulHK, that the 100% the right lead! While the PNGs Cairo produce look normal (only alpha changes), the internal storage format that I use to create textures uses pre-multiplied alpha. I noticed that there were slight color differences in antialiased regions of the PNG (presumably because the premultiplied alpha is divided back before writing the PNG). I.e., a pixel that would be white with 0xaa alpha does not appear as 0xffffffaa but as 0xaaaaaaaa in the binary data. The only question is: how do I blend that data in OpenGL efficiently? Thanks already so much for your help!
Jonas Mechtheim
<opengl><legacy-opengl><font-rendering>
Fonts rendered through textures look thinned
Jonas Mechtheim
# Fonts rendered through textures look thinned

(Asked by: username_0 on 2017-12-18)

I'm rendering fonts using Cairo to surfaces, convert those surfaces to RGBA textures and then display them on GL\_QUADS using orthotogonal projection and alpha blending. When I use Cairo to render directly to the window (i.e., without hardware acceleration), fonts look perfect. When I show them through OpenGL, they look "thinned". Example: <https://i.sstatic.net/DkPbP.jpg>

My texture sizes are powers of two and I do not currently use any scaling (i.e., use the texture coordinates to only show the portion of the texture that actually contains data). I've also tried using the full texture and scaling in the Cairo drawing matrix (i.e., upscaling by Cairo, downloading by OpenGL) which looks even worse.

I believe this has something to do with GL's interpolation, but cannot seem to figure out why it is. When I disable the bilinear GL\_LINEAR texture interpolation to GL\_NEAREST, they look even worse (and blocky, as if it'd ignore the alpha channel). What can I do to make my font textures look more true to their original?

**Tags:** opengl, legacy-opengl, font-rendering

> **Comments:**
> **username_1**: is your lighting turned on for rendering? if so, i suggest trying to turn it off  
> **username_0**: No, not using any lighting.  
> **username_2**: What kind of alpha blending are you using?  
> **username_0**: I use glEnable(GL_ALPHA_TEST) and glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) at the initialization of my program.  
> **username_3**: Is the RGB channel of the font texture all the same colour? It should not contain any anti-aliasing in the RGB channel, only the A channel.  
> **username_0**: @username_3, that the 100% the right lead! While the PNGs Cairo produce look normal (only alpha changes), the internal storage format that I use to create textures uses pre-multiplied alpha. I noticed that there were slight color differences in antialiased regions of the PNG (presumably because the premultiplied alpha is divided back before writing the PNG). I.e., a pixel that would be white with 0xaa alpha does not appear as 0xffffffaa but as 0xaaaaaaaa in the binary data. The only question is: how do I blend that data in OpenGL efficiently? Thanks already so much for your help!  

---

## 1 answers

### Answer by username_3 on 2017-12-20. Score: 3 | Accepted answer

From looking at your example images this looks like a case of Alpha blending being applied to the RGB channel of the font-atlas texture and then again applied via the A channel when rendering.

The tell-tale sign of this is usually a feint dark halo surrounding your glyphs which is caused by the unwanted mid-greys present in the texture being multiplied by alpha.

For font rendering it is typical to have anti-aliasing in the A channel and have your RGB channels a constant colour.


---

