Mercurial > projects > mde
diff mde/resource/FontTexture.d @ 50:f68ae1d667f9
Options: impl template & new OptionsFont class.
Options: impl template to ease creating Options sub-classes.
New OptionsFont class (currently only controls render mode and hinting).
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sun, 01 Jun 2008 18:22:54 +0100 |
parents | bca7e2342d77 |
children | 387a80724c35 |
line wrap: on
line diff
--- a/mde/resource/FontTexture.d Sat May 31 13:10:06 2008 +0100 +++ b/mde/resource/FontTexture.d Sun Jun 01 18:22:54 2008 +0100 @@ -15,12 +15,16 @@ /** Font caching system. * + * This module also serves as the internals to the font module and shouldn't be used except through + * the font module. The two modules could be combined, at a cost to readability. + * * Three types of coordinates get used in the system: FreeType coordinates for each glyph, texture * coordinates, and OpenGL's model/world coordinates (for rendering). The freetype and texture * coords are cartesian (i.e. y increases upwards), although largely this is too abstract to * matter. However, for the model/world coords, y increases downwards. */ module mde.resource.FontTexture; +import mde.Options; import mde.resource.exception; import derelict.freetype.ft; @@ -34,9 +38,6 @@ logger = Log.getLogger ("mde.resource.FontTexture"); } -auto hinting = FT_LOAD_TARGET_NORMAL; //or FT_LOAD_TARGET_LCD (or others) -//FIXME: allow setting lcd filtering -auto lcdFilter = FT_LcdFilter.FT_LCD_FILTER_DEFAULT; //altertives: NONE, LIGHT static const int dimW = 256, dimH = 256; // Texture size const wFactor = 1f / dimW; const hFactor = 1f / dimH; @@ -201,7 +202,8 @@ auto gi = FT_Get_Char_Index (face, chr); auto g = face.glyph; - if (FT_Load_Glyph (face, gi, FT_LOAD_RENDER | hinting)) + // Use renderMode from options, masking bits which are allowable: + if (FT_Load_Glyph (face, gi, FT_LOAD_RENDER | (fontOpts.renderMode & 0xF0000))) throw new fontGlyphException ("Unable to render glyph"); auto b = g.bitmap; @@ -237,9 +239,12 @@ if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_GRAY && b.num_grays == 256) format = GL_LUMINANCE; else if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_LCD || - b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_LCD_V) - format = GL_RGB; - else + b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_LCD_V) { + if (fontOpts.renderMode & RENDER_LCD_BGR) + format = GL_BGR; + else + format = GL_RGB; + } else throw new fontGlyphException ("Unsupported freetype bitmap format"); glTexSubImage2D(GL_TEXTURE_2D, 0, @@ -374,6 +379,24 @@ int nextYPos = 0; // y position for next created line (0 for first line) } +// this bit of renderMode, if set, means read glyph as BGR not RGB when using LCD rendering +enum { RENDER_LCD_BGR = 1 << 30 } +OptionsFont fontOpts; +class OptionsFont : Options { + /* renderMode should be FT_LOAD_TARGET_NORMAL, FT_LOAD_TARGET_LIGHT, FT_LOAD_TARGET_LCD or + * FT_LOAD_TARGET_LCD_V, possibly with bit 31 set (see RENDER_LCD_BGR). + * FT_LOAD_TARGET_MONO is unsupported. + * + * lcdFilter should come from enum FT_LcdFilter: + * FT_LCD_FILTER_NONE, FT_LCD_FILTER_DEFAULT, FT_LCD_FILTER_LIGHT */ + mixin (impl!("int renderMode, lcdFilter;")); + + static this() { + fontOpts = new OptionsFont; + Options.addOptionsClass (fontOpts, "font"); + } +} + struct GlyphAttribs { int x, y; // position within texture int w, h; // bitmap size