Exemplo n.º 1
0
 public Text(ShaderProgram program, BMFont font, string text, Vector3 color, BMFont.Justification justification = BMFont.Justification.Left)
 {
     this.bitmapFont    = font;
     this.Program       = program;
     this.Justification = justification;
     this.Color         = color;
     this.String        = text;
     this.Position      = new Point(0, 0);
 }
Exemplo n.º 2
0
        private void CreateStringInternal(string text, Vector3 color, BMFont.Justification justification, float scale)
        {
            int num1 = 0;

            switch (justification)
            {
            case BMFont.Justification.Center:
                num1 = -this.GetWidth(text) / 2;
                break;

            case BMFont.Justification.Right:
                num1 = -this.GetWidth(text);
                break;
            }
            Vector3 vector3 = Vector3.One * scale;

            for (int index = 0; index < text.Length; ++index)
            {
                BMFont.Character character = this.characters[this.characters.ContainsKey(text[index]) ? text[index] : ' '];
                float            y         = (float)this.Height - character.yoffset;
                int num2 = num1 + 1;
                BMFont.vertices[index * 4]     = vector3 * new Vector3((float)num2, y, 0.0f);
                BMFont.vertices[index * 4 + 1] = vector3 * new Vector3((float)num2, y - character.height, 0.0f);
                BMFont.vertices[index * 4 + 2] = vector3 * new Vector3((float)num2 + character.width, y, 0.0f);
                BMFont.vertices[index * 4 + 3] = vector3 * new Vector3((float)num2 + character.width, y - character.height, 0.0f);
                num1 = num2 + (int)character.xadvance;
                if ((int)text[index] == 95)
                {
                    num1 += 3;
                }
                BMFont.uvs[index * 4]         = new Vector2(character.x1, character.y1);
                BMFont.uvs[index * 4 + 1]     = new Vector2(character.x1, character.y2);
                BMFont.uvs[index * 4 + 2]     = new Vector2(character.x2, character.y1);
                BMFont.uvs[index * 4 + 3]     = new Vector2(character.x2, character.y2);
                BMFont.indices[index * 6]     = index * 4 + 2;
                BMFont.indices[index * 6 + 1] = index * 4;
                BMFont.indices[index * 6 + 2] = index * 4 + 1;
                BMFont.indices[index * 6 + 3] = index * 4 + 3;
                BMFont.indices[index * 6 + 4] = index * 4 + 2;
                BMFont.indices[index * 6 + 5] = index * 4 + 1;
            }
        }
Exemplo n.º 3
0
 public Text(FontSize font, string text, Vector3 color, BMFont.Justification justification = BMFont.Justification.Left)
     : this(Shaders.FontShader, FontFromSize(font), text, color, justification)
 {
 }
Exemplo n.º 4
0
 public Text(ShaderProgram program, BMFont font, string text, BMFont.Justification justification = BMFont.Justification.Left)
     : this(program, font, text, new Vector3(1, 1, 1), justification)
 {
 }
Exemplo n.º 5
0
 public VAO <Vector3, Vector2> CreateString(Material program, string text, Vector3 color, BMFont.Justification justification = BMFont.Justification.Left, float scale = 1f)
 {
     if (text.Length > BMFont.maxStringLength)
     {
         BMFont.maxStringLength = (int)Math.Min((double)int.MaxValue, (double)text.Length * 1.5);
         BMFont.vertices        = new Vector3[BMFont.maxStringLength * 4];
         BMFont.uvs             = new Vector2[BMFont.maxStringLength * 4];
         BMFont.indices         = new int[BMFont.maxStringLength * 6];
     }
     this.CreateStringInternal(text, color, justification, scale);
     return(new VAO <Vector3, Vector2>(program, new VBO <Vector3>(BMFont.vertices, text.Length * 4, BufferTarget.ArrayBuffer, BufferUsageHint.StaticDraw), new VBO <Vector2>(BMFont.uvs, text.Length * 4, BufferTarget.ArrayBuffer, BufferUsageHint.StaticDraw), new string[2] {
         "in_position", "in_uv"
     }, new VBO <int>(BMFont.indices, text.Length * 6, BufferTarget.ElementArrayBuffer, BufferUsageHint.StaticDraw)));
 }
Exemplo n.º 6
0
 public void CreateString(VAO <Vector3, Vector2> vao, string text, Vector3 color, BMFont.Justification justification = BMFont.Justification.Left, float scale = 1f)
 {
     if (vao == null || (int)vao.vaoID == 0)
     {
         return;
     }
     if (vao.VertexCount != text.Length * 6)
     {
         throw new InvalidOperationException("Text length did not match the length of the current vertex array object.");
     }
     this.CreateStringInternal(text, color, justification, scale);
     Gl.BufferSubData <Vector3>(vao.vbos[0].vboID, BufferTarget.ArrayBuffer, BMFont.vertices, text.Length * 4);
     Gl.BufferSubData <Vector2>(vao.vbos[1].vboID, BufferTarget.ArrayBuffer, BMFont.uvs, text.Length * 4);
 }
Exemplo n.º 7
0
 public Text(Text.FontSize font, string text, BMFont.Justification justification = BMFont.Justification.Left)
     : this(Shaders.FontShader, Text.FontFromSize(font), text, Vector3.One, justification)
 {
 }
Exemplo n.º 8
0
 public Text(Material program, BMFont font, string text, BMFont.Justification justification = BMFont.Justification.Left)
     : this(program, font, text, new Vector3(1f, 1f, 1f), justification)
 {
 }