2
$\begingroup$

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?

$\endgroup$
6
  • $\begingroup$ is your lighting turned on for rendering? if so, i suggest trying to turn it off $\endgroup$
    – Tare
    Dec 18, 2017 at 10:51
  • $\begingroup$ No, not using any lighting. $\endgroup$ Dec 18, 2017 at 10:59
  • $\begingroup$ What kind of alpha blending are you using? $\endgroup$
    – Dan Hulme
    Dec 18, 2017 at 11:20
  • $\begingroup$ I use glEnable(GL_ALPHA_TEST) and glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) at the initialization of my program. $\endgroup$ Dec 18, 2017 at 11:21
  • $\begingroup$ 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. $\endgroup$
    – PaulHK
    Dec 18, 2017 at 11:48

1 Answer 1

3
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.