1
votes

I'm making a fast text rendering for an UI system based on OpenGL wich uses subpixel rendering, White text over black background works well with "normal" blending, but black text over white background does not, because the color fringes of the subpixel rendering are multiplied by 0 (because is black), and the subpixel aliasing is lost.

I know this isn't the "correct" way (because i would need to blend each R, G and B subpixel channels separately) but its very fast and looks good almost every situation.

In order to do this, i need to invert the texture color "before" the blending is done, for example:

normal blending is: SourceColor * SourceAlpha + DestColor * (1 - SourceAlpha)

I want this: ((1,1,1) - SourceColor) * SourceAlpha + DestColor * (1 - SourceAlpha)

Is there a way to do this without shaders?? I think that the key is to do two passes with different blending settings but i just can't get it working

I know i could have two textures, one normal and one inverted, but i don't want to waste video memory (because each font requieres an already big texture)

1
"the color fringes of the subpixel rendering are multiplied by 0 (because is black), and the subpixel aliasing is lost." That makes no sense. Unless you pre-multiplied the color with the alpha, that isn't possible. If the fringe alpha is 0, then the alpha must be far from zero. So it should take on the background color (ie: the white it's being blended with). And if you did pre-multiply the color with the alpha (ie: you're using an intensity texture), you shouldn't be multiplying the source color with the source alpha again in the blend stage.Nicol Bolas
The font is pre-rendered on a RGBA bitmap using subpixel rendering (a bitmap font), the problem comes when i want to set the color of the rendered text, if i want it white, i multiply all by (1,1,1) if i want it red, i multiply all by (1,0,0), if i want it black, i multiply all by (0,0,0), but when i do this, the only information remaining on the bitmap is the alpha channel only. It's hard to explain without pictures, but the main idea is fineRafael
What do you mean by "subpixel rendering" in this context? Are you talking about this kind of stuff?Nicol Bolas
yes :) like clear type but with open gl and a lot faster than GDI+, i wrote a software text renderer and then i copy the software bitmap onto an opengl texture. it's for an openGL-based UI framework that i'm developingRafael

1 Answers

0
votes

Give your font texture an alpha channel, then use that to specify the shape of the font, while keeping the colour of every pixel in the texture white, even those pixels outside (which get alpha=0 so they are rgba=1110). Then glColor3f(r,g,b) will colour your texture appropriately (even black) and if you use glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); it will be blended properly.