1

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)

4

1 回答 1

0

给你的字体纹理一个 alpha 通道,然后用它来指定字体的形状,同时保持纹理中每个像素的颜色为白色,即使是外面的那些像素(得到 alpha=0,所以它们是 rgba=1110)。然后glColor3f(r,g,b)将适当地为您的纹理着色(甚至是黑色),如果您使用glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);它将正确混合。

于 2014-08-21T01:55:41.513 回答