Reputation: 2753
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)
Upvotes: 1
Views: 2613
Reputation: 351
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.
Upvotes: 1