示例#1
0
 static public GlyphCache GetCache(int height)
 {
     if (!caches.ContainsKey(height))
     {
         caches[height] = new GlyphCache(height);
     }
     return(caches[height]);
 }
示例#2
0
        public void PrepareBatch()
        {
            if (glyphCache == null)
            {
                glyphCache = GlyphCache.GetCache(Height);
            }

            if (glyphCache.Ready == false)
            {
                return;
            }

            // Add All Glyphs

            //foreach (Text3d t3d in Items)
            //{
            //    foreach (char c in t3d.Text)
            //    {
            //        glyphCache.AddGlyph(c);
            //    }
            //}

            //// Calculate Metrics

            TextObject.Text = "";
            TextObject.FontSize = (float)Height * .50f;

            //System.Drawing.Font font = TextObject.Font;
            //StringFormat sf = new StringFormat();
            //sf.Alignment = StringAlignment.Near;

            //Bitmap bmp = new Bitmap(20, 20);
            //Graphics g = Graphics.FromImage(bmp);
            //// Create Index Buffers

            List<PositionTexture> verts = new List<PositionTexture>();
            foreach (Text3d t3d in Items)
            {
                String text = t3d.Text;
                Vector2d size = Vector2d.Create(1000,100); //g.MeasureString(text, font);

                float factor = .6666f;
                t3d.width = size.X * (float)t3d.scale * factor;
                t3d.height = size.Y * (float)t3d.scale * factor;

                 float left = 0;
                 float top = 0;
                 float fntAdjust = TextObject.FontSize / 128f;

                int charsLeft = text.Length;

                for (int i = 0; i < charsLeft; i++)
                {
                    GlyphItem item = glyphCache.GetGlyphItem(text.Substr(i,1));

                    Rectangle position = Rectangle.Create(left * (float)t3d.scale * factor, 0 * (float)t3d.scale * factor, item.Extents.X * fntAdjust * (float)t3d.scale * factor, item.Extents.Y * fntAdjust * (float)t3d.scale * factor);
                    left += (float)(item.Extents.X * fntAdjust);

                    //System.Diagnostics.Debug.WriteLine((position.Width/position1.Width).ToString() + ", " + (position.Height / position1.Height).ToString());

                    t3d.AddGlyphPoints(verts, item.Size, position, item.UVRect);
                }

            }

            vertCount = verts.Count;
            vertexBuffer = new PositionTextureVertexBuffer(vertCount);

            PositionTexture[] vertBuf = (PositionTexture[])vertexBuffer.Lock(); // Lock the buffer (which will return our structs)

            for (int i = 0; i < vertCount; i++)
            {
                vertBuf[i] = verts[i];
            }

            vertexBuffer.Unlock();

            glyphVersion = glyphCache.Version;
        }
示例#3
0
        public void PrepareBatch()
        {
            if (glyphCache == null)
            {
                glyphCache = GlyphCache.GetCache(Height);
            }

            if (glyphCache.Ready == false)
            {
                return;
            }

            // Add All Glyphs

            //foreach (Text3d t3d in Items)
            //{
            //    foreach (char c in t3d.Text)
            //    {
            //        glyphCache.AddGlyph(c);
            //    }
            //}

            //// Calculate Metrics

            TextObject.Text     = "";
            TextObject.FontSize = (float)Height * .50f;

            //System.Drawing.Font font = TextObject.Font;
            //StringFormat sf = new StringFormat();
            //sf.Alignment = StringAlignment.Near;

            //Bitmap bmp = new Bitmap(20, 20);
            //Graphics g = Graphics.FromImage(bmp);
            //// Create Index Buffers

            List <PositionTexture> verts = new List <PositionTexture>();

            foreach (Text3d t3d in Items)
            {
                String text      = t3d.Text;
                float  left      = 0;
                float  top       = 0;
                float  fntAdjust = TextObject.FontSize / 128f;
                float  factor    = .6666f;
                float  width     = 0;
                float  height    = 0;
                for (int i = 0; i < text.Length; i++)
                {
                    GlyphItem item = glyphCache.GetGlyphItem(text.Substr(i, 1));
                    if (item != null)
                    {
                        width += (float)(item.Extents.X);
                        height = Math.Max(item.Extents.Y, height);
                    }
                }

                Vector2d size = Vector2d.Create(width, height);

                t3d.width  = size.X * (float)t3d.scale * factor * fntAdjust;
                t3d.height = size.Y * (float)t3d.scale * factor * fntAdjust;


                int charsLeft = text.Length;

                for (int i = 0; i < charsLeft; i++)
                {
                    GlyphItem item = glyphCache.GetGlyphItem(text.Substr(i, 1));
                    if (item != null)
                    {
                        Rectangle position = Rectangle.Create(left * (float)t3d.scale * factor, 0 * (float)t3d.scale * factor, item.Extents.X * fntAdjust * (float)t3d.scale * factor, item.Extents.Y * fntAdjust * (float)t3d.scale * factor);
                        left += (float)(item.Extents.X * fntAdjust);

                        //System.Diagnostics.Debug.WriteLine((position.Width/position1.Width).ToString() + ", " + (position.Height / position1.Height).ToString());

                        t3d.AddGlyphPoints(verts, item.Size, position, item.UVRect);
                    }
                }
            }


            vertCount    = verts.Count;
            vertexBuffer = new PositionTextureVertexBuffer(vertCount);

            PositionTexture[] vertBuf = (PositionTexture[])vertexBuffer.Lock(); // Lock the buffer (which will return our structs)

            for (int i = 0; i < vertCount; i++)
            {
                vertBuf[i] = verts[i];
            }

            vertexBuffer.Unlock();

            glyphVersion = glyphCache.Version;
        }
示例#4
0
 public static GlyphCache GetCache(int height)
 {
     if (!caches.ContainsKey(height))
     {
         caches[height] = new GlyphCache(height);
     }
     return caches[height];
 }