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://imgur.com/a/J7IvG

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?

  • $\begingroup$ is your lighting turned on for rendering? if so, i suggest trying to turn it off $\endgroup$
    – Tare
    Dec 18 '17 at 10:51
  • $\begingroup$ No, not using any lighting. $\endgroup$ Dec 18 '17 at 10:59
  • $\begingroup$ What kind of alpha blending are you using? $\endgroup$
    – Dan Hulme
    Dec 18 '17 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 '17 at 11:21
  • 1
    $\begingroup$ Figured it out! GL_ONE, GL_ONE_MINUS_SRC_ALPHA -- and it works perfectly. Since you brought me on the right track, if you want to write an answer I'll accept it! Thanks again so much. $\endgroup$ Dec 18 '17 at 12:43

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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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