Re: [AD] 4.9.20

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Mon, 2010-05-24 at 23:25 +1000, Peter Wang wrote:
> On 2010-05-24, Elias Pschernig <elias.pschernig@xxxxxxxxxx> wrote:
> > On Mon, 2010-05-24 at 22:48 +1000, Peter Wang wrote:
> > > On 2010-05-17, Peter Wang <novalazy@xxxxxxxxxx> wrote:
> > > > Probably overdue for one, so I'll make it this weekend.
> > > 
> > > * I ran into a regression on my machine.  The glyph precision fixes
> > > introduced artefacts, e.g. ex_color and ex_warp_mouse screenshots
> > > attached.  Any ideas?  This is on X11/fglrx.
> > 
> > Does the attached patch fix it? I was sure we fixed this problem in that
> > allegro.cc thread back then - will check if I maybe forgot to apply one
> > of the patches.
> 
> Yes, it fixes it.
> 

However, reading the allegro.cc thread the changes were made for, this
would introduce the old problem again.

Does this alternate patch work? It kinda feels like overkill but I saw
no better way.

Now *all* text drawing is always aligned to integer positions. I'm not
sure how much of a performance penalty the transformations and matrix
inversions cause. One optimization we could do is, have a flag whether
the current transformation is the identity transformation and in that
case skip the alignment. Most likely it doesn't matter.

-- 
Elias Pschernig <elias.pschernig@xxxxxxxxxx>
diff --git a/addons/font/text.c b/addons/font/text.c
index 782399a..d00f2f5 100644
--- a/addons/font/text.c
+++ b/addons/font/text.c
@@ -35,6 +35,33 @@
 
 
 
+// TODO: In case someone actually *wants* to draw their text to
+// sub-pixel positions, for example because multisampling is used,
+// this should not be done. We most likely want either a new alignment
+// flag to disable this, or even a per-font or per-display setting to
+// do so.
+
+ /* Text usually looks best when aligned to pixels -
+  * but if x is 0.5 it may very well end up at an integer
+  * position if the current transformation scales by 2 or
+  * translated x by 0.5. So we simply apply the transformation,
+  * round to nearest integer, and backtransform that.
+  */
+static void align_to_integer_pixel(float *x, float *y)
+{
+   ALLEGRO_TRANSFORM const *t;
+   ALLEGRO_TRANSFORM inverse;
+   t = al_get_current_transform();
+   al_transform_coordinates(t, x, y);
+   *x = round(*x);
+   *y = round(*y);
+   al_copy_transform(t, &inverse);
+   al_invert_transform(&inverse);
+   al_transform_coordinates(&inverse, x, y);
+}
+
+
+
 /* Function: al_draw_ustr
  */
 void al_draw_ustr(const ALLEGRO_FONT *font, float x, float y, int flags,
@@ -54,6 +81,9 @@ void al_draw_ustr(const ALLEGRO_FONT *font, float x, float y, int flags,
       default:
          break;
    }
+
+   align_to_integer_pixel(&x, &y);
+
    font->vtable->render(font, ustr, x, y);
 }
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/