Changeset 51:387a80724c35

Show
Ignore:
Timestamp:
06/02/08 09:34:24 (7 months ago)
Author:
Diggory Hardy <diggory.hardy@gmail.com>
Children:

52:94a4ddb549e5 53:f000d6cd0f74

branch:
default
convert_revision:
3a678fbeb4319d7ecb1a1ffdb271ec0c1b21af18
Message:

Enabled LCD font rendering mode (only tested with freetype's sub-pixel rendering disabled).

committer: Diggory Hardy <diggory.hardy@gmail.com>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • data/L10n/OptionsFont.mtt

    r50 r51  
    11{MT01} 
    22{en-GB} 
    3 <entry|lcdFilter=["LCD filtering","Enable or disable LCD filtering. Note that the FreeType library may be compiled with this support disabled due to patents."]> 
    4 <entry|renderMode=["Font rendering mode","Controls how fonts are rendered: in gray-scale, or for LCDs (with a horizontal (normal) or vertical layout, with an RGB (normal) or BGR sub-pixel mode."]> 
     3<entry|lcdFilter=["LCD filtering","Enable or disable sub-pixel rendering. Note that the FreeType library may be compiled without support due to patent issues."]> 
     4<entry|renderMode=["Font rendering mode","Controls how fonts are rendered: in gray-scale, or for LCDs (with a horizontal (usual) or vertical layout, with an RGB (usual) or BGR sub-pixel mode."]> 
  • data/conf/options.mtt

    r50 r51  
    99{font} 
    1010<int|lcdFilter=0> 
    11 <int|hinting=0> 
     11<int|renderMode=0> 
    1212 
    1313{video} 
  • mde/resource/FontTexture.d

    r50 r51  
    3333import Utf = tango.text.convert.Utf; 
    3434import tango.util.log.Log : Log, Logger; 
     35import tango.io.Stdout; 
    3536 
    3637private Logger logger; 
     
    214215        } 
    215216        glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 
    216         glPixelStorei (GL_UNPACK_ROW_LENGTH, b.pitch); 
     217        //glPixelStorei (GL_UNPACK_ROW_LENGTH, b.pitch); 
    217218         
    218219        GlyphAttribs ga; 
     
    223224        ga.advanceX = g.advance.x >> 6; 
    224225        ga.index    = gi; 
     226        if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_LCD) 
     227            ga.w /= 3; 
     228        if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_LCD_V) 
     229            ga.h /= 3; 
    225230         
    226231        foreach (ref t; tex) { 
     
    237242        glBindTexture(GL_TEXTURE_2D, ga.texID); 
    238243        GLenum format; 
    239         if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_GRAY && b.num_grays == 256) 
     244        ubyte[] buffer; // use our own pointer, since for LCD modes we need to perform a conversion 
     245        if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_GRAY && b.num_grays == 256) { 
     246            buffer = b.buffer[0..b.pitch*b.rows]; 
    240247            format = GL_LUMINANCE; 
    241         else if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_LCD || 
    242                  b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_LCD_V) { 
    243             if (fontOpts.renderMode & RENDER_LCD_BGR) 
    244                 format = GL_BGR; 
    245             else 
    246                 format = GL_RGB; 
     248        } else if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_LCD) { 
     249            // NOTE: Can't seem to get OpenGL to read freetype's RGB buffers properly, so convent. 
     250            /* NOTE: Sub-pixel rendering probably also needs filtering. I haven't tried, since it's 
     251             * disabled in my build of the library. For a tutorial on the filtering, see: 
     252             * http://dmedia.dprogramming.com/?n=Tutorials.TextRendering1 */ 
     253            buffer = new ubyte[b.width*b.rows]; 
     254            for (uint i = 0; i < b.rows; ++i) 
     255                for (uint j = 0; j < b.width; j+= 3) 
     256            { 
     257                buffer[i*b.width + j + 0] = b.buffer[i*b.pitch + j + 0]; 
     258                buffer[i*b.width + j + 1] = b.buffer[i*b.pitch + j + 1]; 
     259                buffer[i*b.width + j + 2] = b.buffer[i*b.pitch + j + 2]; 
     260            } 
     261             
     262            format = (fontOpts.renderMode & RENDER_LCD_BGR) ? GL_BGR : GL_RGB; 
     263        } else if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_LCD_V) { 
     264            // NOTE: Notes above apply. Only in this case converting the buffers seems essential. 
     265            buffer = new ubyte[b.width*b.rows]; 
     266            for (uint i = 0; i < b.rows; ++i) 
     267                for (uint j = 0; j < b.width; ++j) 
     268            { 
     269                // i/3 is the "real" row, b.width*3 is our width (with subpixels), j is column, 
     270                // i%3 is sub-pixel (R/G/B). i/3*3 necessary to round to multiple of 3 
     271                buffer[i/3*b.width*3 + 3*j + i%3] = b.buffer[i*b.pitch + j]; 
     272            } 
     273             
     274            format = (fontOpts.renderMode & RENDER_LCD_BGR) ? GL_BGR : GL_RGB; 
    247275        } else 
    248276            throw new fontGlyphException ("Unsupported freetype bitmap format"); 
     
    252280                        ga.w, ga.h, 
    253281                        format, GL_UNSIGNED_BYTE, 
    254                         cast(void*) b.buffer); 
     282                        cast(void*) buffer.ptr); 
    255283         
    256284        cachedGlyphs[chr] = ga; 
     
    353381        line.yPos = nextYPos; 
    354382        line.height = attr.h * EXTRA_H; 
     383        Stdout.format ("Creating new line of height {}", line.height).newline; 
    355384        line.length = attr.w; 
    356385        size_t i = 0; 
     
    389418     * 
    390419     * lcdFilter should come from enum FT_LcdFilter: 
    391      * FT_LCD_FILTER_NONE, FT_LCD_FILTER_DEFAULT, FT_LCD_FILTER_LIGHT */ 
     420     * FT_LCD_FILTER_NONE = 0, FT_LCD_FILTER_DEFAULT = 1, FT_LCD_FILTER_LIGHT = 2 */ 
    392421    mixin (impl!("int renderMode, lcdFilter;")); 
    393422     
  • mde/resource/font.d

    r50 r51  
    7272            } 
    7373             
    74             // Set LCD filtering method 
    75             if (FT_Library_SetLcdFilter(library, cast(FT_LcdFilter)fontOpts.lcdFilter)) { 
     74            // Set LCD filtering method (note: FT_Library_SetLcdFilter can still complain with 
     75            // FT_LcdFilter.FT_LCD_FILTER_NONE). 
     76            if (fontOpts.lcdFilter && FT_Library_SetLcdFilter(library, cast(FT_LcdFilter)fontOpts.lcdFilter)) { 
    7677                // If setting failed, leave at default (disabled status). Note: it is disabled by 
    7778                // default because the code isn't compiled in by default, to avoid patents. 
    78                 logger.warn ("Bad/unsupported LCD filter option; disabling."); 
     79                logger.warn ("Bad/unsupported LCD filter option; disabling LCD filtering."); 
     80                logger.warn ("Your FreeType 2 library may compiled without support for LCD/sub-pixel rendering."); 
    7981                Options.setInt ("font", "lcdFilter", FT_LcdFilter.FT_LCD_FILTER_NONE); 
     82            } 
     83            const RMF = FT_LOAD_TARGET_MONO | FT_LOAD_TARGET_LCD | FT_LOAD_TARGET_LCD_V; 
     84            if (fontOpts.renderMode & RMF && fontOpts.lcdFilter == 0) { 
     85                logger.warn ("Using LCD rendering when LCD filtering is disabled has no effect; disabling."); 
     86                Options.setInt ("font", "renderMode", FT_LOAD_TARGET_NORMAL); 
    8087            } 
    8188             
     
    209216     * font being changed or if cache.cacheVer < 0. */ 
    210217    void updateBlock (char[] str, ref TextBlock cache) { 
    211         fontTex.updateCache (face, str, cache); 
     218        try { 
     219            fontTex.updateCache (face, str, cache); 
     220        } catch (Exception e) { 
     221            logger.warn ("Exception while drawing text: "~e.msg); 
     222        } 
    212223    } 
    213224     
  • mde/sdl.d

    r50 r51  
    129129     */ 
    130130    try { 
    131         DerelictGL.loadVersions(GLVersion.Version13); 
     131        DerelictGL.loadVersions(GLVersion.Version21); 
    132132    } catch (SharedLibProcLoadException e) { 
    133133        logger.warn ("Loading OpenGL version 1.3 failed:");