Re: [AD] [ alleg-Bugs-3152695 ] text rending is broken with OpenGL

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


On 2011-01-07, Elias Pschernig <elias.pschernig@xxxxxxxxxx> wrote:
> On Thu, 2011-01-06 at 23:47 +0000, SourceForge.net wrote:
> > Bugs item #3152695, was opened at 2011-01-06 23:47
> > Summary: text rending is broken with OpenGL
> > 
> > Initial Comment:
> > Under Windows, when forced texture compression is enabled (many
> > low-end devices like my EEE PC have it on by default to save memory),
> > font rendering doesn't work. Haven't investigate a lot yet, but likely
> > glTexSubImage2D fails due to changed alignment requirements.
> > 
> 
> Attached is a patch which fixes this. The problem is present on at least
> two test PCs (one with an ATI card, one with an Intel card) so might be
> wide-spread. The patch simply (unconditionally) makes glyphs in a font
> sheet aligned to 4 pixel boundaries and also gives them a size which is
> a multiple of 4 pixels.
> 
> With D3D and proper OpenGL drivers there is no problem. It also might be
> Windows only. So could add a check to only do this when compiling for
> Windows (although it would be nice to confirm it's Windows only first)
> and add a runtime check to only do it when the bitmap is an OpenGL
> bitmap. But aligning to 4-pixels seemed harmless enough to me to leave
> that out for now.


> diff --git a/addons/ttf/ttf.c b/addons/ttf/ttf.c
> index 6218d84..4b635a2 100644
> --- a/addons/ttf/ttf.c
> +++ b/addons/ttf/ttf.c
> @@ -9,6 +9,18 @@
>  #include <ft2build.h>
>  #include FT_FREETYPE_H
>  
> +/* Some low-end drivers enable automatic S3TC compression, which
> + * requires glTexSubImage2D to only work on multiples of aligned
> + * 4x4 pixel blocks with some buggy OpenGL drivers.
> + * There's not much we can do about that in general - if the user
> + * locks a portion of a bitmap not conformin to this it will fail
> + * with such a driver.

Might we not be able to compensate for it, by locking a region which
might be larger than requested?  Not that it's important to do right now.

> + * 
> + * However in many programs this is no problem at all safe for rendering
> + * glyphs and simply aligning to 4 pixels here fixes it.
> + */
> +#define ALIGN_TO_4_PIXEL
> +
>  ALLEGRO_DEBUG_CHANNEL("font")
>  
>  typedef struct ALLEGRO_TTF_GLYPH_DATA
> @@ -114,9 +126,17 @@ static ALLEGRO_BITMAP* create_glyph_cache(ALLEGRO_FONT const *f, int w,
>  
>      p_cache = _al_vector_ref_back(&data->cache_bitmaps);
>      cache = *p_cache;
> +    
> +    #ifdef ALIGN_TO_4_PIXEL
> +    w = (w + 3) & ~3;
> +    h = (h + 3) & ~3;
> +    #endif

Make a function instead of repeating the slightly obscure expression
everywhere.

Peter




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