[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43876] trunk/blender/source: Fix for aliased fonts in the game engine.

Dalai Felinto dfelinto at gmail.com
Wed Feb 8 19:27:47 CET 2012


I'm having some problems with that patch as well.

Attached file at:
http://projects.blender.org/tracker/?func=detail&atid=127&aid=29882&group_id=9

We may need to roll it back for now, and try to address those issues after
2.62 release. 2.62 final release is too close

--
Dalai
www.dalaifelinto.com

2012/2/8 Mitchell Stokes <mogurijin at gmail.com>

> I think this broke the framerate and profile display in some cases:
> http://www.pasteall.org/pic/26095
>
> I haven't yet been able to find a simple case that shows this. That
> screenshot is from this project:
> https://code.google.com/p/conceptrpg2/
>
> --Mitchell Stokes
>
> On Fri, Feb 3, 2012 at 5:51 PM, Alex Fraser <alex at phatcore.com> wrote:
> > Revision: 43876
> >
> http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43876
> > Author:   z0r
> > Date:     2012-02-04 01:51:59 +0000 (Sat, 04 Feb 2012)
> > Log Message:
> > -----------
> > 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.
> >
> > Modified Paths:
> > --------------
> >    trunk/blender/source/blender/blenfont/BLF_api.h
> >    trunk/blender/source/blender/blenfont/intern/blf_glyph.c
> >    trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp
> >    trunk/blender/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
> >
> > Modified: trunk/blender/source/blender/blenfont/BLF_api.h
> > ===================================================================
> > --- trunk/blender/source/blender/blenfont/BLF_api.h     2012-02-04
> 00:36:55 UTC (rev 43875)
> > +++ trunk/blender/source/blender/blenfont/BLF_api.h     2012-02-04
> 01:51:59 UTC (rev 43876)
> > @@ -197,6 +197,7 @@
> >  #define BLF_KERNING_DEFAULT (1<<3)
> >  #define BLF_MATRIX (1<<4)
> >  #define BLF_ASPECT (1<<5)
> > +#define BLF_TEXFILTER (1<<6)
> >
> >  #define BLF_DRAW_STR_DUMMY_MAX 1024
> >
> >
> > Modified: trunk/blender/source/blender/blenfont/intern/blf_glyph.c
> > ===================================================================
> > --- trunk/blender/source/blender/blenfont/intern/blf_glyph.c
>  2012-02-04 00:36:55 UTC (rev 43875)
> > +++ trunk/blender/source/blender/blenfont/intern/blf_glyph.c
>  2012-02-04 01:51:59 UTC (rev 43876)
> > @@ -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 @@
> >        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 @@
> >
> >  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 @@
> >
> >                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);
> >
> > Modified:
> trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp
> > ===================================================================
> > --- trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp
>  2012-02-04 00:36:55 UTC (rev 43875)
> > +++ trunk/blender/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp
>  2012-02-04 01:51:59 UTC (rev 43876)
> > @@ -136,8 +136,8 @@
> >        /* the actual drawing */
> >        glColor4fv(color);
> >
> > +       BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT|BLF_TEXFILTER);
> >        /* multiply the text matrix by the object matrix */
> > -       BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT);
> >        BLF_matrix(fontid, mat);
> >
> >        /* aspect is the inverse scale that allows you to increase */
> > @@ -149,7 +149,7 @@
> >        BLF_position(fontid, 0, 0, 0);
> >        BLF_draw(fontid, (char *)text, 65535);
> >
> > -       BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT);
> > +       BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT|BLF_TEXFILTER);
> >  }
> >
> >  void BL_print_gamedebug_line(const char* text, int xco, int yco, int
> width, int height)
> >
> > Modified:
> trunk/blender/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
> > ===================================================================
> > ---
> trunk/blender/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
> 2012-02-04 00:36:55 UTC (rev 43875)
> > +++
> trunk/blender/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
> 2012-02-04 01:51:59 UTC (rev 43876)
> > @@ -294,8 +294,8 @@
> >        /* the actual drawing */
> >        glColor3fv(color);
> >
> > +       BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT|BLF_TEXFILTER);
> >        /* multiply the text matrix by the object matrix */
> > -       BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT);
> >        BLF_matrix(fontid, mat);
> >
> >        /* aspect is the inverse scale that allows you to increase */
> > @@ -307,7 +307,7 @@
> >        BLF_position(fontid, 0, 0, 0);
> >        BLF_draw(fontid, text, 65535);
> >
> > -       BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT);
> > +       BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT|BLF_TEXFILTER);
> >        glEnable(GL_DEPTH_TEST);
> >  }
> >
> >
> > _______________________________________________
> > Bf-blender-cvs mailing list
> > Bf-blender-cvs at blender.org
> > http://lists.blender.org/mailman/listinfo/bf-blender-cvs
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers
>


More information about the Bf-committers mailing list