Exemplo n.º 1
0
        public GLFont(Font font, GLFontEngine eng)
        {
            Engine = eng;
            GL.BlendFunc(0, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            Engine.Shaders.ColorMultShader.Bind();
            Name               = font.Name;
            Size               = (int)font.Size;
            Bold               = font.Bold;
            Italic             = font.Italic;
            Height             = font.Height;
            CharacterLocations = new List <RectangleF>();
            StringFormat sf = new StringFormat(StringFormat.GenericTypographic);

            sf.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.FitBlackBox | StringFormatFlags.NoWrap;
            Internal_Font   = font;
            Bitmap bmp = new Bitmap(Engine.bwidth, Engine.bheight);

            GL.BindTexture(TextureTarget.Texture2DArray, Engine.Texture3D);
            Characters = Engine.textfile;
            using (Graphics gfx = Graphics.FromImage(bmp))
            {
                gfx.Clear(Color.Transparent);
                gfx.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                float X = 6;
                float Y = 0;
                gfx.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, 5, (int)Height));
                Brush brush = new SolidBrush(Color.White);
                for (int i = 0; i < Engine.textfile.Length; i++)
                {
                    string chr    = Engine.textfile[i] == '\t' ? "    " : Engine.textfile[i].ToString();
                    float  nwidth = gfx.MeasureString(chr, font, new PointF(0, 0), sf).Width;
                    if (X + nwidth >= Engine.bwidth)
                    {
                        Y += Height + 4;
                        X  = 0;
                    }
                    gfx.DrawString(chr, font, brush, new PointF(X, Y), sf);
                    CharacterLocations.Add(new RectangleF(X, Y, nwidth, Height));
                    X += (float)Math.Ceiling(nwidth) + 4;
                }
            }
            BitmapData data = bmp.LockBits(new Rectangle(0, 0, Engine.bwidth, Engine.bheight), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            GL.TexSubImage3D(TextureTarget.Texture2DArray, 0, 0, 0, cZ, Engine.bwidth, Engine.bheight, 1, OpenTK.Graphics.OpenGL4.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
            TexZ = cZ;
            cZ++;
            cZ = cZ % 24;
            // TODO: Handle > 24 fonts more cleanly
            bmp.UnlockBits(data);
        }
Exemplo n.º 2
0
 public FontSetEngine(GLFontEngine fengine)
 {
     GLFonts = fengine;
 }
Exemplo n.º 3
0
 public TextVBO(GLFontEngine fengine)
 {
     Engine = fengine;
 }