Changeset 51:387a80724c35
- Timestamp:
- 06/02/08 09:34:24 (7 months ago)
- Children:
- Files:
-
- data/L10n/OptionsFont.mtt (modified) (1 diff)
- data/conf/options.mtt (modified) (1 diff)
- mde/resource/FontTexture.d (modified) (7 diffs)
- mde/resource/font.d (modified) (2 diffs)
- mde/sdl.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
data/L10n/OptionsFont.mtt
r50 r51 1 1 {MT01} 2 2 {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 9 9 {font} 10 10 <int|lcdFilter=0> 11 <int| hinting=0>11 <int|renderMode=0> 12 12 13 13 {video} mde/resource/FontTexture.d
r50 r51 33 33 import Utf = tango.text.convert.Utf; 34 34 import tango.util.log.Log : Log, Logger; 35 import tango.io.Stdout; 35 36 36 37 private Logger logger; … … 214 215 } 215 216 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 216 glPixelStorei (GL_UNPACK_ROW_LENGTH, b.pitch);217 //glPixelStorei (GL_UNPACK_ROW_LENGTH, b.pitch); 217 218 218 219 GlyphAttribs ga; … … 223 224 ga.advanceX = g.advance.x >> 6; 224 225 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; 225 230 226 231 foreach (ref t; tex) { … … 237 242 glBindTexture(GL_TEXTURE_2D, ga.texID); 238 243 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]; 240 247 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; 247 275 } else 248 276 throw new fontGlyphException ("Unsupported freetype bitmap format"); … … 252 280 ga.w, ga.h, 253 281 format, GL_UNSIGNED_BYTE, 254 cast(void*) b .buffer);282 cast(void*) buffer.ptr); 255 283 256 284 cachedGlyphs[chr] = ga; … … 353 381 line.yPos = nextYPos; 354 382 line.height = attr.h * EXTRA_H; 383 Stdout.format ("Creating new line of height {}", line.height).newline; 355 384 line.length = attr.w; 356 385 size_t i = 0; … … 389 418 * 390 419 * 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 */ 392 421 mixin (impl!("int renderMode, lcdFilter;")); 393 422 mde/resource/font.d
r50 r51 72 72 } 73 73 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)) { 76 77 // If setting failed, leave at default (disabled status). Note: it is disabled by 77 78 // 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."); 79 81 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); 80 87 } 81 88 … … 209 216 * font being changed or if cache.cacheVer < 0. */ 210 217 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 } 212 223 } 213 224 mde/sdl.d
r50 r51 129 129 */ 130 130 try { 131 DerelictGL.loadVersions(GLVersion.Version 13);131 DerelictGL.loadVersions(GLVersion.Version21); 132 132 } catch (SharedLibProcLoadException e) { 133 133 logger.warn ("Loading OpenGL version 1.3 failed:");
