snoob at September 11th, 2013 13:59 — #1
Actually I've migrated my FreeType font renderer from OpenGL 2.x to OpenGL 3.x support. Now rendering is supported on both platforms without any code change. So far so good. However I got a question to the GLSL fragment shader routine. Before I've migrated my source I've used this call for font sprite rasterization:
uniform sampler2D DiffuseMap;
varying vec4 vColor;
varying vec2 vTexCoord0;
gl_FragColor = vec4(vColor.rgb, texture2D(DiffuseMap, vTexCoord0).a);
With this snipped I got pin sharp results on font rendering also on blending: Pin sharp rendering sample But this snipped is not working on OpenGL 3.x. If I use this snipped I only got the sprite quads rasterized, filled with the vertex attribute color. The single font characters are not visible. By this reason I changed the snipped to:
vec4 vTexColor = texture2D(DiffuseMap, vTexCoord0.st);
gl_FragColor = (vTexColor.r, vTexColor.r, vTexColor.r, vTexColor.r)*vColor;
With this snipped the font rendering is working with both renderer. But on both renderer the font looks now unsharpen, especially on blending: Unsharpen rendering sample. For blending I use: GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_FUNC_ADD.
Could someone explain me what is the difference between both routines and why the first one doesn't work with OpenGL 3.x? Is it possible that alpha value mapping is not supported? Maybe knows someone how I could sharpen the rendering results if I have to use the second snipped?
v71 at September 11th, 2013 18:12 — #2
I have the same problem , and i am still waiting an answer from freetype2 support , actually seems like the option is unsupported, i tried every blend mode, nothing worked for me as well.
vilem_otte at September 11th, 2013 19:02 — #3
This is just one of the things that forced me to create my own fonts (distance field ones), achieving good enough quality text without the need for 3rd party libraries (like FreeType).
Alpha value mapping is definitely supported, although a bug might be in your shader. Try using some GLSL version and sticking heavily to it's specifications. Also are you sure that blending is correctly set up and enabled (try it with just 0.5 value in alpha - whether it does render semi transparent stuff)?
Also it is not common to use .rgb indexing instead of .xyz (I know that some Mobility Radeon drivers screams warnings about these, but runs), try to avoid them.
stainless at September 12th, 2013 04:33 — #4
gl_FragColor = vec4(vColor.xyz, texture2D(DiffuseMap, vTexCoord0.st).w);
snoob at September 12th, 2013 07:45 — #5
Thanks for your feedback guys. Meanwhile I could solve the issue based on Stainless snipped with a short modification:
gl_FragColor = vec4(vColor.xyz, texture(DiffuseMap, vTexCoord0).y);
Now I'ts working with both renderer with pin sharp results, also on blending. What I doesn't know until yet is that the GLSL .rgba indexing is mapped to the texture color channel values, while .xyzw indexing only to vector positions. By this reason .a indexing has no effect on OpenGL 3.x while the internal texture format is RG8 and there is no alpha value channel given.
v71 at September 13th, 2013 04:44 — #6
I have used Snoob's snippet but i still get blurred fonts
stainless at September 13th, 2013 08:19 — #7
Check the opengl state, do you have blending enabled? What is the screen pixel format?
v71 at September 13th, 2013 12:30 — #8
Yes i have blending enable, if i disable it i get only white quads , and hte screen format is RGBA 32 bits color and 32bits for depth
thenut at September 13th, 2013 23:41 — #9
What do you mean by blurred fonts? Is the library properly rasterizing the font? Are you mip-mapping the font (you shouldn't be)? Make sure you add 1 pixel padding to your glyphs so that OpenGL's bilinear filter doesn't render the edges from adjacent glyphs. Perhaps obvious, but don't scale the fonts. Always rasterize the highest resolution and scale down.
I stopped using FreeType long ago as it's a fairly bloated library and rarely do you distribute true type fonts (for legal reasons mostly). I prefer to create bitmap fonts from a bitmap font converter or render them through Blender. It's something worth considering, unless you really need the flexibility of having vector fonts on hand.
snoob at September 14th, 2013 07:09 — #10
Fell free to check my FreeType font plug-in and renderer sources: http://sourceforge.net/p/binrevengine/code/HEAD/tree/
The actual sources are in an early alpha version. There are a lot of things I've to do, but it works and may be a help.
rombust at September 26th, 2013 08:28 — #11
The ClanLib SDK uses OpenGL subpixel rendering without problems. This is with freetype (on Linux) and without (on Windows).
It uses the blend function: src = blend_constant_color dest = blend_one_minus_src_color src_alpha = blend_zero dest_alpha = blend_one
Using FT_LOAD_TARGET_LCD and FT_RENDER_MODE_LCD to obtain the subpixel glyphs