Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Fraser <alex@phatcore.com>2012-02-04 05:51:59 +0400
committerAlex Fraser <alex@phatcore.com>2012-02-04 05:51:59 +0400
commita05fdb837b89f2fba04587e99d0eecaa9cf174c3 (patch)
tree3739d95c3a2b10d1ae7cc8a0723ba3cb19924e0a /source/blender/blenfont/intern
parentdc97e07134c48aacf5e3de4436d70e7b71fbecaa (diff)
Fix for aliased fonts in the game engine.
- Mipmaps are generated in BLF when drawing text in-game. In that case, padding around each glyph is increased to prevent bleeding. - Texture filtering is turned on for in-game text. - All glyphs are now "twisted": the leading edge is brought a small distance forward, to prevent z-fighting in overlapping (kerned) glyphs. This happens both in the game engine and the rest of the UI, but should have no effect in the UI due to Z-compression in the clipping matrix. Reviewed and approved by bdiego; see patch [#29882] in the tracker. Tested by dfelinto.
Diffstat (limited to 'source/blender/blenfont/intern')
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index f0cfcdc97b9..0e7cbb8cf1c 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -54,6 +54,8 @@
#include "blf_internal_types.h"
#include "blf_internal.h"
+#define _BLF_PADDING 3
+#define _BLF_MIPMAP_LEVELS 3
GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, int size, int dpi)
{
@@ -87,7 +89,11 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
gc->cur_tex= -1;
gc->x_offs= 0;
gc->y_offs= 0;
- gc->pad= 3;
+ /* Increase padding for each mipmap level: 0->3, 1->4, 2->6, 3->10, ... */
+ if (font->flags & BLF_TEXFILTER)
+ gc->pad= pow(2, _BLF_MIPMAP_LEVELS) + 2;
+ else
+ gc->pad= _BLF_PADDING;
gc->num_glyphs= font->face->num_glyphs;
gc->rem_glyphs= font->face->num_glyphs;
@@ -296,13 +302,17 @@ void blf_glyph_free(GlyphBLF *g)
static void blf_texture_draw(float uv[2][2], float dx, float y1, float dx1, float y2)
{
-
+ /* When a string is being rendered as individual glyphs (as in the game
+ * engine), the leading edge needs to be raised a fraction to prevent
+ * z-fighting for kerned characters. - z0r */
+ float twist = (dx1 - dx) * 0.0002;
+
glBegin(GL_QUADS);
glTexCoord2f(uv[0][0], uv[0][1]);
- glVertex2f(dx, y1);
+ glVertex3f(dx, y1, twist);
glTexCoord2f(uv[0][0], uv[1][1]);
- glVertex2f(dx, y2);
+ glVertex3f(dx, y2, twist);
glTexCoord2f(uv[1][0], uv[1][1]);
glVertex2f(dx1, y2);
@@ -405,6 +415,15 @@ int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
glBindTexture(GL_TEXTURE_2D, g->tex);
glTexSubImage2D(GL_TEXTURE_2D, 0, g->xoff, g->yoff, g->width, g->height, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap);
+ if (font->flags & BLF_TEXFILTER) {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL,
+ _BLF_MIPMAP_LEVELS);
+ glGenerateMipmap(GL_TEXTURE_2D);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+ GL_LINEAR_MIPMAP_LINEAR);
+ }
glPopClientAttrib();
g->uv[0][0]= ((float)g->xoff) / ((float)gc->p2_width);