diff mde/resource/FontTexture.d @ 53:f000d6cd0f74

Changes to paths, command line arguments and font LCD rendering. Use "./" instead of "" as default install dir on windows. Implemented a command-line argument parser. Changes to LCD filter/render-mode option handling after testing what actually happens. Changed some FontTexture messages and internals.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 05 Jun 2008 17:16:52 +0100
parents 387a80724c35
children 9e1f05fbbcef
line wrap: on
line diff
--- a/mde/resource/FontTexture.d	Mon Jun 02 14:34:24 2008 +0100
+++ b/mde/resource/FontTexture.d	Thu Jun 05 17:16:52 2008 +0100
@@ -32,7 +32,6 @@
 
 import Utf = tango.text.convert.Utf;
 import tango.util.log.Log : Log, Logger;
-import tango.io.Stdout;
 
 private Logger logger;
 static this () {
@@ -74,7 +73,7 @@
     void updateCache (FT_Face face, char[] str, ref TextBlock cache)
     {
         debug scope (failure)
-                logger.warn ("updateCache failed");
+                logger.error ("updateCache failed");
         
         if (cache.cacheVer == cacheVer)	// Existing cache is up-to-date
             return;
@@ -165,7 +164,7 @@
     void drawTextCache (FT_Face face, char[] str, ref TextBlock cache, int x, int y) {
         updateCache (face, str, cache);	// update if necessary
         debug scope (failure)
-                logger.warn ("drawTextCache failed");
+                logger.error ("drawTextCache failed");
         
         glEnable (GL_TEXTURE_2D);
         glEnable(GL_BLEND);
@@ -198,7 +197,7 @@
     
     void addGlyph (FT_Face face, dchar chr) {
         debug scope (failure)
-                logger.warn ("FontTexture.addGlyph failed!");
+                logger.error ("FontTexture.addGlyph failed!");
         
         auto gi = FT_Get_Char_Index (face, chr);
         auto g = face.glyph;
@@ -208,11 +207,6 @@
             throw new fontGlyphException ("Unable to render glyph");
         
         auto b = g.bitmap;
-        if (b.pitch != b.width) {
-            char[128] tmp;
-            logger.warn (logger.format (tmp, "b.pitch is {}, b.width is {}", b.pitch, b.width));
-            //throw new fontGlyphException ("Unsupported freetype bitmap: b.pitch != b.width");
-        }
         glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
         //glPixelStorei (GL_UNPACK_ROW_LENGTH, b.pitch);
         
@@ -234,7 +228,7 @@
         }
         // if here, no existing texture had the room for the glyph so create a new texture
         // NOTE: check if using more than one texture impacts performance due to texture switching
-        logger.info ("Creating a font texture.");
+        logger.info ("Creating a new font texture.");
         tex ~= TexPacker.create();
         assert (tex[$-1].addGlyph (ga), "Failed to fit glyph in a new texture but addGlyph didn't throw");
         
@@ -243,6 +237,7 @@
         GLenum format;
         ubyte[] buffer;	// use our own pointer, since for LCD modes we need to perform a conversion
         if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_GRAY && b.num_grays == 256) {
+            assert (b.pitch == b.width, "Have assumed b.pitch == b.width for gray glyphs.");
             buffer = b.buffer[0..b.pitch*b.rows];
             format = GL_LUMINANCE;
         } else if (b.pixel_mode == FT_Pixel_Mode.FT_PIXEL_MODE_LCD) {
@@ -357,6 +352,9 @@
         if (attr.w > dimW || attr.h > dimH)
             throw new fontGlyphException ("Glyph too large to fit texture!");
         
+        attr.texID = texID;		// Set now. Possibly reset if new texture is needed.
+        if (attr.w == 0) return true;	// 0 sized glyph; x and y are unimportant.
+        
         bool cantFitExtraLine = nextYPos + attr.h >= dimH;
         foreach (ref line; lines) {
             if (line.length + attr.w <= dimW &&		// if sufficient length and
@@ -380,7 +378,6 @@
         Line line;
         line.yPos = nextYPos;
         line.height = attr.h * EXTRA_H;
-        Stdout.format ("Creating new line of height {}", line.height).newline;
         line.length = attr.w;
         size_t i = 0;
         while (i < lines.length && lines[i].height < line.height) ++i;
@@ -389,7 +386,6 @@
         
         attr.x = 0;	// first glyph in the line
         attr.y = line.yPos;
-        attr.texID = texID;
         return true;
     }